chore: import upstream snapshot with attribution
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import type { GetProfileParams, GetProfileResponse } from '@/tools/linkedin/types'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
export const linkedInGetProfileTool: ToolConfig<GetProfileParams, GetProfileResponse> = {
|
||||
id: 'linkedin_get_profile',
|
||||
name: 'Get LinkedIn Profile',
|
||||
description: 'Retrieve your LinkedIn profile information',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'linkedin',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'Access token for LinkedIn API',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: () => 'https://api.linkedin.com/v2/userinfo',
|
||||
method: 'GET',
|
||||
headers: (params: GetProfileParams): Record<string, string> => ({
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
'X-Restli-Protocol-Version': '2.0.0',
|
||||
}),
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response): Promise<GetProfileResponse> => {
|
||||
if (!response.ok) {
|
||||
return {
|
||||
success: false,
|
||||
output: {},
|
||||
error: `Failed to get profile: ${response.statusText}`,
|
||||
}
|
||||
}
|
||||
|
||||
const profile = await response.json()
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
profile: {
|
||||
id: profile.sub,
|
||||
name: profile.name,
|
||||
email: profile.email,
|
||||
picture: profile.picture,
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export { linkedInGetProfileTool } from './get_profile'
|
||||
export { linkedInSharePostTool } from './share_post'
|
||||
@@ -0,0 +1,158 @@
|
||||
import { getErrorMessage } from '@sim/utils/errors'
|
||||
import type {
|
||||
LinkedInProfileOutput,
|
||||
ProfileIdExtractor,
|
||||
SharePostParams,
|
||||
SharePostResponse,
|
||||
} from '@/tools/linkedin/types'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
// Helper function to extract profile ID from various response formats
|
||||
const extractProfileId: ProfileIdExtractor = (output: unknown): string | null => {
|
||||
if (typeof output === 'object' && output !== null) {
|
||||
const profileOutput = output as LinkedInProfileOutput
|
||||
return profileOutput.profile?.id || profileOutput.sub || profileOutput.id || null
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export const linkedInSharePostTool: ToolConfig<SharePostParams, SharePostResponse> = {
|
||||
id: 'linkedin_share_post',
|
||||
name: 'Share Post on LinkedIn',
|
||||
description: 'Share a post to your personal LinkedIn feed',
|
||||
version: '1.0.0',
|
||||
|
||||
oauth: {
|
||||
required: true,
|
||||
provider: 'linkedin',
|
||||
},
|
||||
|
||||
params: {
|
||||
accessToken: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'hidden',
|
||||
description: 'Access token for LinkedIn API',
|
||||
},
|
||||
text: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'The text content of your LinkedIn post',
|
||||
},
|
||||
visibility: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Who can see this post: "PUBLIC" or "CONNECTIONS" (default: "PUBLIC")',
|
||||
},
|
||||
},
|
||||
|
||||
// First request: Get user profile to obtain the person URN
|
||||
request: {
|
||||
url: () => 'https://api.linkedin.com/v2/userinfo',
|
||||
method: 'GET',
|
||||
headers: (params: SharePostParams) => ({
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
'X-Restli-Protocol-Version': '2.0.0',
|
||||
}),
|
||||
},
|
||||
|
||||
// Use postProcess to make the actual post creation request
|
||||
postProcess: async (profileResult, params, executeTool) => {
|
||||
try {
|
||||
// Extract profile from the first request
|
||||
if (!profileResult.success || !profileResult.output) {
|
||||
return {
|
||||
success: false,
|
||||
output: {},
|
||||
error: 'Failed to fetch user profile',
|
||||
}
|
||||
}
|
||||
|
||||
// Get profile data from output
|
||||
const profileOutput = profileResult.output as LinkedInProfileOutput
|
||||
const authorId = extractProfileId(profileOutput)
|
||||
|
||||
if (!authorId) {
|
||||
return {
|
||||
success: false,
|
||||
output: {},
|
||||
error: 'Could not extract LinkedIn profile ID from response',
|
||||
}
|
||||
}
|
||||
|
||||
const authorUrn = `urn:li:person:${authorId}`
|
||||
|
||||
// Create the post
|
||||
const postData = {
|
||||
author: authorUrn,
|
||||
lifecycleState: 'PUBLISHED',
|
||||
specificContent: {
|
||||
'com.linkedin.ugc.ShareContent': {
|
||||
shareCommentary: {
|
||||
text: params.text,
|
||||
},
|
||||
shareMediaCategory: 'NONE',
|
||||
},
|
||||
},
|
||||
visibility: {
|
||||
'com.linkedin.ugc.MemberNetworkVisibility': params.visibility || 'PUBLIC',
|
||||
},
|
||||
}
|
||||
|
||||
const response = await fetch('https://api.linkedin.com/v2/ugcPosts', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${params.accessToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
'X-Restli-Protocol-Version': '2.0.0',
|
||||
},
|
||||
body: JSON.stringify(postData),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.text()
|
||||
return {
|
||||
success: false,
|
||||
output: {},
|
||||
error: `LinkedIn API error: ${error}`,
|
||||
}
|
||||
}
|
||||
|
||||
const result = await response.json()
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: {
|
||||
postId: result.id,
|
||||
},
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
output: {},
|
||||
error: getErrorMessage(error, 'Unknown error'),
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
transformResponse: async (response: Response): Promise<SharePostResponse> => {
|
||||
// This handles the initial profile fetch response
|
||||
if (!response.ok) {
|
||||
return {
|
||||
success: false,
|
||||
output: {},
|
||||
error: `Failed to fetch profile: ${response.statusText}`,
|
||||
}
|
||||
}
|
||||
|
||||
const profile = await response.json()
|
||||
|
||||
// Return profile data for postProcess to use
|
||||
return {
|
||||
success: true,
|
||||
output: profile,
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
import type { ToolResponse } from '@/tools/types'
|
||||
|
||||
interface LinkedInProfile {
|
||||
sub: string
|
||||
name: string
|
||||
given_name: string
|
||||
family_name: string
|
||||
email?: string
|
||||
picture?: string
|
||||
email_verified?: boolean
|
||||
}
|
||||
|
||||
interface LinkedInPost {
|
||||
author: string // URN format: urn:li:person:abc123
|
||||
lifecycleState: 'PUBLISHED'
|
||||
specificContent: {
|
||||
'com.linkedin.ugc.ShareContent': {
|
||||
shareCommentary: {
|
||||
text: string
|
||||
}
|
||||
shareMediaCategory: 'NONE' | 'ARTICLE' | 'IMAGE'
|
||||
media?: Array<{
|
||||
status: 'READY'
|
||||
description: {
|
||||
text: string
|
||||
}
|
||||
media: string // URN format
|
||||
title: {
|
||||
text: string
|
||||
}
|
||||
}>
|
||||
}
|
||||
}
|
||||
visibility: {
|
||||
'com.linkedin.ugc.MemberNetworkVisibility': 'PUBLIC' | 'CONNECTIONS'
|
||||
}
|
||||
}
|
||||
|
||||
export type LinkedInResponse = {
|
||||
success: boolean
|
||||
output: {
|
||||
postId?: string
|
||||
profile?: {
|
||||
id: string
|
||||
name: string
|
||||
email?: string
|
||||
picture?: string
|
||||
}
|
||||
}
|
||||
error?: string
|
||||
}
|
||||
|
||||
// Tool-specific type definitions
|
||||
export interface LinkedInProfileOutput {
|
||||
profile?: {
|
||||
id: string
|
||||
name?: string
|
||||
email?: string
|
||||
picture?: string
|
||||
}
|
||||
sub?: string
|
||||
id?: string
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
export interface SharePostParams {
|
||||
accessToken: string
|
||||
text: string
|
||||
visibility?: 'PUBLIC' | 'CONNECTIONS' | 'LOGGED_IN'
|
||||
mediaUrls?: string
|
||||
}
|
||||
|
||||
export interface SharePostResponse extends ToolResponse {
|
||||
output: {
|
||||
postId?: string
|
||||
postUrl?: string
|
||||
visibility?: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface GetProfileParams {
|
||||
accessToken: string
|
||||
}
|
||||
|
||||
export interface GetProfileResponse extends ToolResponse {
|
||||
output: LinkedInProfileOutput
|
||||
}
|
||||
|
||||
export type ProfileIdExtractor = (output: unknown) => string | null
|
||||
Reference in New Issue
Block a user