@zhafron/opencode-kiro-auth 1.4.11 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/constants.d.ts +0 -1
- package/dist/constants.js +0 -9
- package/dist/core/account/account-selector.d.ts +25 -0
- package/dist/core/account/account-selector.js +84 -0
- package/dist/core/account/usage-tracker.d.ts +17 -0
- package/dist/core/account/usage-tracker.js +39 -0
- package/dist/core/auth/auth-handler.d.ts +15 -0
- package/dist/core/auth/auth-handler.js +33 -0
- package/dist/core/auth/idc-auth-method.d.ts +17 -0
- package/dist/core/auth/idc-auth-method.js +200 -0
- package/dist/core/auth/token-refresher.d.ts +22 -0
- package/dist/core/auth/token-refresher.js +53 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.js +9 -0
- package/dist/core/request/error-handler.d.ts +30 -0
- package/dist/core/request/error-handler.js +113 -0
- package/dist/core/request/request-handler.d.ts +27 -0
- package/dist/core/request/request-handler.js +199 -0
- package/dist/core/request/response-handler.d.ts +5 -0
- package/dist/core/request/response-handler.js +61 -0
- package/dist/core/request/retry-strategy.d.ts +18 -0
- package/dist/core/request/retry-strategy.js +28 -0
- package/dist/infrastructure/database/account-cache.d.ts +14 -0
- package/dist/infrastructure/database/account-cache.js +44 -0
- package/dist/infrastructure/database/account-repository.d.ts +12 -0
- package/dist/infrastructure/database/account-repository.js +64 -0
- package/dist/infrastructure/index.d.ts +7 -0
- package/dist/infrastructure/index.js +7 -0
- package/dist/infrastructure/transformers/event-stream-parser.d.ts +7 -0
- package/dist/infrastructure/transformers/event-stream-parser.js +115 -0
- package/dist/infrastructure/transformers/history-builder.d.ts +5 -0
- package/dist/infrastructure/transformers/history-builder.js +171 -0
- package/dist/infrastructure/transformers/message-transformer.d.ts +6 -0
- package/dist/infrastructure/transformers/message-transformer.js +102 -0
- package/dist/infrastructure/transformers/tool-call-parser.d.ts +4 -0
- package/dist/infrastructure/transformers/tool-call-parser.js +45 -0
- package/dist/infrastructure/transformers/tool-transformer.d.ts +2 -0
- package/dist/infrastructure/transformers/tool-transformer.js +19 -0
- package/dist/kiro/auth.d.ts +0 -1
- package/dist/kiro/auth.js +0 -7
- package/dist/plugin/accounts.d.ts +0 -1
- package/dist/plugin/accounts.js +4 -4
- package/dist/plugin/cli.d.ts +2 -1
- package/dist/plugin/cli.js +67 -2
- package/dist/plugin/config/schema.js +4 -4
- package/dist/plugin/models.d.ts +0 -2
- package/dist/plugin/models.js +0 -6
- package/dist/plugin/request.d.ts +0 -2
- package/dist/plugin/request.js +5 -282
- package/dist/plugin/response.d.ts +2 -5
- package/dist/plugin/response.js +3 -161
- package/dist/plugin/storage/migrations.d.ts +2 -0
- package/dist/plugin/storage/migrations.js +109 -0
- package/dist/plugin/storage/sqlite.js +5 -56
- package/dist/plugin/streaming/index.d.ts +2 -0
- package/dist/plugin/streaming/index.js +2 -0
- package/dist/plugin/streaming/openai-converter.d.ts +2 -0
- package/dist/plugin/streaming/openai-converter.js +68 -0
- package/dist/plugin/streaming/stream-parser.d.ts +5 -0
- package/dist/plugin/streaming/stream-parser.js +136 -0
- package/dist/plugin/streaming/stream-state.d.ts +5 -0
- package/dist/plugin/streaming/stream-state.js +59 -0
- package/dist/plugin/streaming/stream-transformer.d.ts +1 -0
- package/dist/plugin/{streaming.js → streaming/stream-transformer.js} +6 -268
- package/dist/plugin/streaming/types.d.ts +25 -0
- package/dist/plugin/streaming/types.js +2 -0
- package/dist/plugin/sync/kiro-cli-parser.d.ts +8 -0
- package/dist/plugin/sync/kiro-cli-parser.js +72 -0
- package/dist/plugin/sync/kiro-cli.js +1 -73
- package/dist/plugin/types.d.ts +0 -13
- package/dist/plugin.d.ts +6 -6
- package/dist/plugin.js +16 -512
- package/package.json +11 -3
- package/dist/plugin/storage/migration.d.ts +0 -1
- package/dist/plugin/storage/migration.js +0 -54
- package/dist/plugin/streaming.d.ts +0 -3
|
@@ -1,82 +1,10 @@
|
|
|
1
1
|
import { Database } from 'bun:sqlite';
|
|
2
|
-
import { createHash } from 'node:crypto';
|
|
3
2
|
import { existsSync } from 'node:fs';
|
|
4
|
-
import { homedir, platform } from 'node:os';
|
|
5
|
-
import { join } from 'node:path';
|
|
6
3
|
import { createDeterministicAccountId } from '../accounts';
|
|
7
4
|
import * as logger from '../logger';
|
|
8
5
|
import { kiroDb } from '../storage/sqlite';
|
|
9
6
|
import { fetchUsageLimits } from '../usage';
|
|
10
|
-
|
|
11
|
-
const override = process.env.KIROCLI_DB_PATH;
|
|
12
|
-
if (override)
|
|
13
|
-
return override;
|
|
14
|
-
const p = platform();
|
|
15
|
-
if (p === 'win32')
|
|
16
|
-
return join(process.env.APPDATA || join(homedir(), 'AppData', 'Roaming'), 'kiro-cli', 'data.sqlite3');
|
|
17
|
-
if (p === 'darwin')
|
|
18
|
-
return join(homedir(), 'Library', 'Application Support', 'kiro-cli', 'data.sqlite3');
|
|
19
|
-
return join(homedir(), '.local', 'share', 'kiro-cli', 'data.sqlite3');
|
|
20
|
-
}
|
|
21
|
-
function safeJsonParse(value) {
|
|
22
|
-
if (typeof value !== 'string')
|
|
23
|
-
return null;
|
|
24
|
-
try {
|
|
25
|
-
return JSON.parse(value);
|
|
26
|
-
}
|
|
27
|
-
catch {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function normalizeExpiresAt(input) {
|
|
32
|
-
if (typeof input === 'number') {
|
|
33
|
-
// Heuristic: < 10^10 is likely seconds.
|
|
34
|
-
return input < 10_000_000_000 ? input * 1000 : input;
|
|
35
|
-
}
|
|
36
|
-
if (typeof input === 'string' && input.trim()) {
|
|
37
|
-
const t = new Date(input).getTime();
|
|
38
|
-
if (!Number.isNaN(t) && t > 0)
|
|
39
|
-
return t;
|
|
40
|
-
const n = Number(input);
|
|
41
|
-
if (Number.isFinite(n) && n > 0)
|
|
42
|
-
return normalizeExpiresAt(n);
|
|
43
|
-
}
|
|
44
|
-
return 0;
|
|
45
|
-
}
|
|
46
|
-
function findClientCredsRecursive(input) {
|
|
47
|
-
const root = input;
|
|
48
|
-
if (!root || typeof root !== 'object')
|
|
49
|
-
return {};
|
|
50
|
-
const stack = [root];
|
|
51
|
-
const visited = new Set();
|
|
52
|
-
while (stack.length) {
|
|
53
|
-
const cur = stack.pop();
|
|
54
|
-
if (!cur || typeof cur !== 'object')
|
|
55
|
-
continue;
|
|
56
|
-
if (visited.has(cur))
|
|
57
|
-
continue;
|
|
58
|
-
visited.add(cur);
|
|
59
|
-
const clientId = cur.client_id || cur.clientId;
|
|
60
|
-
const clientSecret = cur.client_secret || cur.clientSecret;
|
|
61
|
-
if (typeof clientId === 'string' && typeof clientSecret === 'string') {
|
|
62
|
-
if (clientId && clientSecret)
|
|
63
|
-
return { clientId, clientSecret };
|
|
64
|
-
}
|
|
65
|
-
if (Array.isArray(cur)) {
|
|
66
|
-
for (const v of cur)
|
|
67
|
-
stack.push(v);
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
for (const v of Object.values(cur))
|
|
71
|
-
stack.push(v);
|
|
72
|
-
}
|
|
73
|
-
return {};
|
|
74
|
-
}
|
|
75
|
-
function makePlaceholderEmail(authMethod, region, clientId, profileArn) {
|
|
76
|
-
const seed = `${authMethod}:${region}:${clientId || ''}:${profileArn || ''}`;
|
|
77
|
-
const h = createHash('sha256').update(seed).digest('hex').slice(0, 16);
|
|
78
|
-
return `${authMethod}-placeholder+${h}@awsapps.local`;
|
|
79
|
-
}
|
|
7
|
+
import { findClientCredsRecursive, getCliDbPath, makePlaceholderEmail, normalizeExpiresAt, safeJsonParse } from './kiro-cli-parser';
|
|
80
8
|
export async function syncFromKiroCli() {
|
|
81
9
|
const dbPath = getCliDbPath();
|
|
82
10
|
if (!existsSync(dbPath))
|
package/dist/plugin/types.d.ts
CHANGED
|
@@ -39,11 +39,6 @@ export interface ManagedAccount {
|
|
|
39
39
|
lastSync?: number;
|
|
40
40
|
lastUsed?: number;
|
|
41
41
|
}
|
|
42
|
-
export interface UsageMetadata {
|
|
43
|
-
usedCount: number;
|
|
44
|
-
limitCount: number;
|
|
45
|
-
lastSync: number;
|
|
46
|
-
}
|
|
47
42
|
export interface CodeWhispererMessage {
|
|
48
43
|
userInputMessage?: {
|
|
49
44
|
content: string;
|
|
@@ -112,11 +107,3 @@ export interface PreparedRequest {
|
|
|
112
107
|
conversationId: string;
|
|
113
108
|
}
|
|
114
109
|
export type AccountSelectionStrategy = 'sticky' | 'round-robin' | 'lowest-usage';
|
|
115
|
-
export interface StreamEvent {
|
|
116
|
-
type: string;
|
|
117
|
-
message?: any;
|
|
118
|
-
content_block?: any;
|
|
119
|
-
delta?: any;
|
|
120
|
-
index?: number;
|
|
121
|
-
usage?: any;
|
|
122
|
-
}
|
package/dist/plugin.d.ts
CHANGED
|
@@ -4,13 +4,13 @@ export declare const createKiroPlugin: (id: string) => ({ client, directory }: a
|
|
|
4
4
|
loader: (getAuth: any) => Promise<{
|
|
5
5
|
apiKey: string;
|
|
6
6
|
baseURL: string;
|
|
7
|
-
fetch(input: any, init?: any)
|
|
7
|
+
fetch: (input: any, init?: any) => Promise<Response>;
|
|
8
8
|
}>;
|
|
9
9
|
methods: {
|
|
10
10
|
id: string;
|
|
11
11
|
label: string;
|
|
12
|
-
type:
|
|
13
|
-
authorize: (inputs?: any) => Promise<
|
|
12
|
+
type: "oauth";
|
|
13
|
+
authorize: (inputs?: any) => Promise<any>;
|
|
14
14
|
}[];
|
|
15
15
|
};
|
|
16
16
|
}>;
|
|
@@ -20,13 +20,13 @@ export declare const KiroOAuthPlugin: ({ client, directory }: any) => Promise<{
|
|
|
20
20
|
loader: (getAuth: any) => Promise<{
|
|
21
21
|
apiKey: string;
|
|
22
22
|
baseURL: string;
|
|
23
|
-
fetch(input: any, init?: any)
|
|
23
|
+
fetch: (input: any, init?: any) => Promise<Response>;
|
|
24
24
|
}>;
|
|
25
25
|
methods: {
|
|
26
26
|
id: string;
|
|
27
27
|
label: string;
|
|
28
|
-
type:
|
|
29
|
-
authorize: (inputs?: any) => Promise<
|
|
28
|
+
type: "oauth";
|
|
29
|
+
authorize: (inputs?: any) => Promise<any>;
|
|
30
30
|
}[];
|
|
31
31
|
};
|
|
32
32
|
}>;
|