(linearAdapter: LinearAdapter)
| 150 | } |
| 151 | |
| 152 | export function createLinearBotPlatform(linearAdapter: LinearAdapter): BotPlatform { |
| 153 | return { |
| 154 | platform: PLATFORM.LINEAR, |
| 155 | // TODO: point at a dedicated Linear docs page once it's published. |
| 156 | documentationUrl: 'https://kilo.ai/docs/code-with-ai/platforms/linear', |
| 157 | // Linear comments are visible to every workspace member, so the |
| 158 | // generic `/api/chat/link-account` flow (which trusts the URL-embedded |
| 159 | // `identity.userId` as the Linear user to link) cannot be used safely. |
| 160 | // We bounce through a Linear OAuth identity-proof round-trip instead. |
| 161 | usesGenericLinkAccountRoute: false, |
| 162 | |
| 163 | async getIdentity({ message }) { |
| 164 | const raw = getLinearRaw(message); |
| 165 | if (!raw) { |
| 166 | throw new Error('Expected LinearRawMessage with organizationId in message.raw'); |
| 167 | } |
| 168 | return { |
| 169 | platform: PLATFORM.LINEAR, |
| 170 | teamId: raw.organizationId, |
| 171 | userId: message.author.userId, |
| 172 | }; |
| 173 | }, |
| 174 | |
| 175 | isEnabledForBot(integration) { |
| 176 | const metadata = integration.metadata as { bot_enabled?: boolean } | null; |
| 177 | return metadata?.bot_enabled === true; |
| 178 | }, |
| 179 | |
| 180 | canHandleMessage: () => true, |
| 181 | |
| 182 | async promptLinkAccount({ thread, identity, platformIntegration }) { |
| 183 | const url = new URL(LINEAR_LINK_PATH, APP_URL); |
| 184 | url.searchParams.set( |
| 185 | 'token', |
| 186 | createLinearLinkToken({ |
| 187 | platformIntegrationId: platformIntegration.id, |
| 188 | organizationId: identity.teamId, |
| 189 | }) |
| 190 | ); |
| 191 | |
| 192 | // Linear has no ephemeral messages or interactive buttons — post a |
| 193 | // markdown link directly into the thread. The token does NOT carry |
| 194 | // a Linear user id; the clicker proves their identity via OAuth. |
| 195 | await thread.post({ |
| 196 | markdown: |
| 197 | 'To use Kilo from this Linear workspace you first need to link your Linear account to Kilo. ' + |
| 198 | `[Link your Kilo account](${url.toString()}) to continue. ` + |
| 199 | 'After linking, mention me again on this issue.', |
| 200 | }); |
| 201 | }, |
| 202 | |
| 203 | async withAuthContext({ platformIntegration, fn }) { |
| 204 | const organizationId = platformIntegration.platform_installation_id; |
| 205 | if (!organizationId) { |
| 206 | throw new Error( |
| 207 | `No Linear organization id for platform integration ${platformIntegration.id}` |
| 208 | ); |
| 209 | } |
no outgoing calls
no test coverage detected