MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / createLinearBotPlatform

Function createLinearBotPlatform

apps/web/src/lib/bot/platforms/linear.ts:152–230  ·  view source on GitHub ↗
(linearAdapter: LinearAdapter)

Source from the content-addressed store, hash-verified

150}
151
152export 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 }

Callers 2

linear.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected