Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fix-import-jwt-share-url.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@kilocode/cli": patch
"kilo-code": patch
---

Accept JWT share tokens when importing a session from a Kilo share URL.
4 changes: 2 additions & 2 deletions packages/opencode/src/cli/cmd/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export type ShareData =
| { type: "model"; data: unknown }

// kilocode_change start
/** Extract share ID from a Kilo share URL like https://app.kilo.ai/s/abc123 */
/** Extract share token from a Kilo share URL like https://app.kilo.ai/s/<jwt> */
export function parseShareUrl(url: string): string | null {
const match = url.match(/^https?:\/\/app\.kilo\.ai\/s\/([a-zA-Z0-9_-]+)$/)
const match = url.match(/^https?:\/\/app\.kilo\.ai\/s\/([A-Za-z0-9_.-]+)$/)
return match ? match[1] : null
}
// kilocode_change end
Expand Down
8 changes: 4 additions & 4 deletions packages/opencode/src/kilo-sessions/kilo-sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1068,12 +1068,12 @@ export namespace KiloSessions {
throw new Error(`Unable to share session ${sessionId}: ${response.status} ${response.statusText}`)
}

const result = (await response.json()) as { public_id?: string }
if (!result.public_id) {
throw new Error(`Unable to share session ${sessionId}: server did not return a public id`)
const result = (await response.json()) as { share_token?: string }
if (!result.share_token) {
throw new Error(`Unable to share session ${sessionId}: server did not return a share token`)
}

const url = `https://app.kilo.ai/s/${result.public_id}`
const url = `https://app.kilo.ai/s/${result.share_token}`

await save(sessionId, {
...current,
Expand Down
7 changes: 7 additions & 0 deletions packages/opencode/test/cli/import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ test("parses valid Kilo share URLs", () => {
)
expect(parseShareUrl("https://app.kilo.ai/s/Jsj3hNIW")).toBe("Jsj3hNIW")
expect(parseShareUrl("https://app.kilo.ai/s/test_id-123")).toBe("test_id-123")
// kilocode_change start
expect(
parseShareUrl(
"https://app.kilo.ai/s/eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJzZXNfMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMiJ9.signature",
),
).toBe("eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJzZXNfMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMiJ9.signature")
// kilocode_change end
})

test("rejects invalid URLs", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/opencode/test/kilocode/session-share.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ it.instance("shares and unshares sessions through Kilo public URLs", () => {
const url = String(input)
urls.push(url)
if (url.endsWith("/api/user")) return new Response("{}", { status: 200 })
if (url.endsWith("/share")) return Response.json({ public_id: "public-1" })
if (url.endsWith("/share")) return Response.json({ share_token: "public-1" })
if (url.endsWith("/unshare")) return new Response(null, { status: 200 })
return new Response("{}", { status: 200 })
},
Expand Down
Loading