sliccy 3.26.0 → 3.27.0
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/dist/node-server/_cloud_core/src/cone-config/index.d.ts +77 -0
- package/dist/node-server/_cloud_core/src/cone-config/index.d.ts.map +1 -0
- package/dist/node-server/_cloud_core/src/cone-config/index.js +209 -0
- package/dist/node-server/_cloud_core/src/index.d.ts +1 -0
- package/dist/node-server/_cloud_core/src/index.d.ts.map +1 -1
- package/dist/node-server/_cloud_core/src/index.js +6 -0
- package/dist/node-server/_cloud_core/src/operations/resume.d.ts +13 -0
- package/dist/node-server/_cloud_core/src/operations/resume.d.ts.map +1 -1
- package/dist/node-server/_cloud_core/src/operations/resume.js +117 -3
- package/dist/node-server/_cloud_core/src/operations/start.d.ts +3 -0
- package/dist/node-server/_cloud_core/src/operations/start.d.ts.map +1 -1
- package/dist/node-server/_cloud_core/src/operations/start.js +8 -0
- package/dist/node-server/_cloud_core/src/types.d.ts +7 -0
- package/dist/node-server/_cloud_core/src/types.d.ts.map +1 -1
- package/dist/node-server/_cloud_core/tests/cone-config/cone-config.test.d.ts +2 -0
- package/dist/node-server/_cloud_core/tests/cone-config/cone-config.test.d.ts.map +1 -0
- package/dist/node-server/_cloud_core/tests/cone-config/cone-config.test.js +119 -0
- package/dist/node-server/_cloud_core/tests/resume-cone-config.test.d.ts +2 -0
- package/dist/node-server/_cloud_core/tests/resume-cone-config.test.d.ts.map +1 -0
- package/dist/node-server/_cloud_core/tests/resume-cone-config.test.js +57 -0
- package/dist/node-server/_cloud_core/tests/start-cone-config.test.d.ts +2 -0
- package/dist/node-server/_cloud_core/tests/start-cone-config.test.d.ts.map +1 -0
- package/dist/node-server/_cloud_core/tests/start-cone-config.test.js +65 -0
- package/dist/node-server/hosted-bootstrap.d.ts +9 -13
- package/dist/node-server/hosted-bootstrap.js +51 -8
- package/dist/node-server/index.js +2 -0
- package/dist/node-server/secrets-reload-endpoint.d.ts +7 -0
- package/dist/node-server/secrets-reload-endpoint.js +7 -0
- package/dist/ui/assets/{adobe-CqrEgLNi.js → adobe-CBPHs44a.js} +1 -1
- package/dist/ui/assets/adobe-DTgONesS.js +2 -0
- package/dist/ui/assets/{agent-bridge-DLoHpCQV.js → agent-bridge-C1hh0i7r.js} +1 -1
- package/dist/ui/assets/{agent-message-to-chat-DAB_RuwN.js → agent-message-to-chat-O6uJ723d.js} +1 -1
- package/dist/ui/assets/{anthropic-M0Z3vEYG.js → anthropic-B5t7Ca-d.js} +1 -1
- package/dist/ui/assets/{anthropic-BlLRyvML.js → anthropic-Ch8C5Pbq.js} +2 -2
- package/dist/ui/assets/{apps-BEDw2CRe.js → apps-BYrUryR9.js} +1 -1
- package/dist/ui/assets/{azure-openai-k9R7HvYf.js → azure-openai-CN_aYYaR.js} +1 -1
- package/dist/ui/assets/azure-openai-DWt3QAgp.js +1 -0
- package/dist/ui/assets/azure-openai-responses-CIJsH0Te.js +1 -0
- package/dist/ui/assets/{azure-openai-responses-DDHZ47hL.js → azure-openai-responses-CtSe7H8g.js} +1 -1
- package/dist/ui/assets/{biome_wasm-CTxVnl7G.js → biome_wasm-4wW5MOGX.js} +1 -1
- package/dist/ui/assets/{bsh-watchdog-CkHKF91q.js → bsh-watchdog-BaAZ6UaW.js} +1 -1
- package/dist/ui/assets/{cdp-BwSaINyX.js → cdp-CsX5Muk6.js} +4 -4
- package/dist/ui/assets/{cdp-ws-page-bridge-BZg_arql.js → cdp-ws-page-bridge-APPmL2Hp.js} +1 -1
- package/dist/ui/assets/cloud-DhBwfVPK.js +1 -0
- package/dist/ui/assets/cloud-DwpQLDy4.css +1 -0
- package/dist/ui/assets/{common-BXJu90Rc.js → common-thb06dCK.js} +1 -1
- package/dist/ui/assets/connect-surface-euFcBnSi.js +103 -0
- package/dist/ui/assets/cost-command-DE2EIDSB.js +1 -0
- package/dist/ui/assets/{es-48UZpaVV.js → es-D4KetpAc.js} +1 -1
- package/dist/ui/assets/{follower-sprinkle-bridge-jm6CXbz1.js → follower-sprinkle-bridge-Dtb83g3c.js} +1 -1
- package/dist/ui/assets/github-B4rjRfXb.js +2 -0
- package/dist/ui/assets/github-copilot-B6u_s0W5.js +2 -0
- package/dist/ui/assets/{github-copilot-C2tBzQ4u.js → github-copilot-DJng6jj6.js} +1 -1
- package/dist/ui/assets/github-ybjlK69B.js +1 -0
- package/dist/ui/assets/{google-BZiIgeFw.js → google-DOIQpMhU.js} +1 -1
- package/dist/ui/assets/google-TbDfFmOp.js +1 -0
- package/dist/ui/assets/{google-shared-BcE4P_yG.js → google-shared-BMZeJV03.js} +1 -1
- package/dist/ui/assets/{google-shared--uY0bz2s.js → google-shared-CgrrvCwj.js} +1 -1
- package/dist/ui/assets/{google-vertex-D9lRdxr2.js → google-vertex-BTUls1U6.js} +1 -1
- package/dist/ui/assets/{google-vertex-CwZ7zLwx.js → google-vertex-D41QKayp.js} +1 -1
- package/dist/ui/assets/hosted-config-apply-BuSIcpqX.js +1 -0
- package/dist/ui/assets/{intercepted-oauth-D2d-qzF2.js → intercepted-oauth-CR0mw9LN.js} +1 -1
- package/dist/ui/assets/{kernel-worker-qa_GIQ_O.js → kernel-worker-BXAud9Z1.js} +20 -20
- package/dist/ui/assets/{lick-ws-bridge-lwDDVM1H.js → lick-ws-bridge-D75cMY-e.js} +1 -1
- package/dist/ui/assets/{local-llm-s5TSv3VA.js → local-llm-B86K8ORa.js} +2 -2
- package/dist/ui/assets/{magick-wasm-Dg17fb8P.js → magick-wasm-oD6EBbqw.js} +1 -1
- package/dist/ui/assets/{main-pholQCCK.js → main-B019n563.js} +20 -20
- package/dist/ui/assets/{mistral-8auDf7Jd.js → mistral-D9vhuj4T.js} +2 -2
- package/dist/ui/assets/{mistral-DWhJFHHy.js → mistral-Do2y-xFg.js} +1 -1
- package/dist/ui/assets/{nodejs-BMz0dS6L.js → nodejs-CthPDCGp.js} +1 -1
- package/dist/ui/assets/{nuke-command-Ct7N3bt9.js → nuke-command-CjjYDkoR.js} +1 -1
- package/dist/ui/assets/{oauth-B_aSN2_9.js → oauth-B-V_js5f.js} +1 -1
- package/dist/ui/assets/oauth-bootstrap-ZkgyY3Xg.js +2 -0
- package/dist/ui/assets/{oauth-service-CSONhiAr.js → oauth-service-BWOcUJw9.js} +1 -1
- package/dist/ui/assets/{oauth-service-CWG5aTag.js → oauth-service-Br_yPLR6.js} +1 -1
- package/dist/ui/assets/{offscreen-client-VoSRhHbL.js → offscreen-client-BdcOXcJx.js} +1 -1
- package/dist/ui/assets/{onboarding-orchestrator-sLJH00ba.js → onboarding-orchestrator-C9E2JadQ.js} +1 -1
- package/dist/ui/assets/openai-codex-BIZ504Bw.js +1 -0
- package/dist/ui/assets/{openai-codex-kcOw2Vdc.js → openai-codex-F2kdI04k.js} +1 -1
- package/dist/ui/assets/{openai-codex-responses-DUtA00zk.js → openai-codex-responses-CNWmFqRF.js} +1 -1
- package/dist/ui/assets/{openai-codex-responses-OSkMGGNT.js → openai-codex-responses-_sMq0AiZ.js} +5 -5
- package/dist/ui/assets/openai-completions-GGocHcbj.js +5 -0
- package/dist/ui/assets/openai-responses-DNuJ9yc7.js +1 -0
- package/dist/ui/assets/{openai-responses-D4FZMY-V.js → openai-responses-DwcEkrK8.js} +1 -1
- package/dist/ui/assets/{openai-responses-shared-brUOwaY9.js → openai-responses-shared-BiUW_Dn7.js} +1 -1
- package/dist/ui/assets/{openai-responses-shared-D1uRqOzX.js → openai-responses-shared-mOjUd3Og.js} +4 -4
- package/dist/ui/assets/{openrouter-yGOsBjDk.js → openrouter-C9NnDTzU.js} +1 -1
- package/dist/ui/assets/openrouter-CMmA6hqx.js +1 -0
- package/dist/ui/assets/{panel-rpc-handlers-HU3Mwr0v.js → panel-rpc-handlers-Cd7suWDn.js} +1 -1
- package/dist/ui/assets/{provider-B2-C4Uc0.js → provider-DXYeDIH1.js} +2 -2
- package/dist/ui/assets/{provider-B-Z77g0j.js → provider-nOzo_7kY.js} +1 -1
- package/dist/ui/assets/provider-store-access-CdnAWCB6.js +1 -0
- package/dist/ui/assets/provider-store-access-DHFL36BG.js +1 -0
- package/dist/ui/assets/{proxied-fetch-fouZMPr0.js → proxied-fetch-0NkyhbS7.js} +1 -1
- package/dist/ui/assets/{pyodide-D0Y6NsDy.js → pyodide-X54n8NWa.js} +2 -2
- package/dist/ui/assets/{remote-terminal-view-B5-dZXNa.js → remote-terminal-view-j_4iQ-W9.js} +1 -1
- package/dist/ui/assets/{secret-env-BTjJvpLw.js → secret-env-BZxlB3a6.js} +1 -1
- package/dist/ui/assets/{slicc-editor-BjOPBIPG.js → slicc-editor-B0fkqMs_.js} +1 -1
- package/dist/ui/assets/{spawn-8eiTHKfU.js → spawn-j2ecIGUI.js} +1 -1
- package/dist/ui/assets/{sql-wasm-B1Tsjops.js → sql-wasm-zp3i_QTF.js} +1 -1
- package/dist/ui/assets/{store-DRudQTL3.js → store-CU9DQRf6.js} +1 -1
- package/dist/ui/assets/{tray-leave-runtime-Cs2vcG7Q.js → tray-leave-runtime-ClhhoTRH.js} +1 -1
- package/dist/ui/assets/{typescript-CpCsC2U4.js → typescript-CsbUCNp2.js} +1 -1
- package/dist/ui/assets/{upgrade-detection-B_PXlklw.js → upgrade-detection-BRm2MCd-.js} +1 -1
- package/dist/ui/assets/{web-oHZ28cEx.js → web-D7zVwxWL.js} +1 -1
- package/dist/ui/assets/{ws-subscribers-BKg2braa.js → ws-subscribers-7G878iZM.js} +1 -1
- package/dist/ui/assets/{xai-grok-BIGY0Sih.js → xai-grok-CTEqN2oB.js} +1 -1
- package/dist/ui/assets/{xai-grok-CrDfS2o4.js → xai-grok-CdSZRqyL.js} +1 -1
- package/dist/ui/index.html +1 -1
- package/dist/ui/packages/webapp/cloud/index.html +44 -6
- package/dist/ui/packages/webapp/index.html +1 -1
- package/package.json +1 -1
- package/dist/ui/assets/adobe-ccKB80po.js +0 -2
- package/dist/ui/assets/azure-openai-9hADAfm8.js +0 -1
- package/dist/ui/assets/azure-openai-responses-BylSyLnY.js +0 -1
- package/dist/ui/assets/cloud-CZM-12lk.js +0 -1
- package/dist/ui/assets/cloud-CyzxzXN0.css +0 -1
- package/dist/ui/assets/cost-command-BoMWdldA.js +0 -1
- package/dist/ui/assets/github-BJKlBN9d.js +0 -2
- package/dist/ui/assets/github-C4AFIIt2.js +0 -1
- package/dist/ui/assets/github-copilot-BgQsh-to.js +0 -2
- package/dist/ui/assets/google-CnX2AAb4.js +0 -1
- package/dist/ui/assets/oauth-bootstrap-g4iVUmBv.js +0 -2
- package/dist/ui/assets/openai-codex-vn0_7U9V.js +0 -1
- package/dist/ui/assets/openai-completions-XCsW7xai.js +0 -5
- package/dist/ui/assets/openai-responses-DYkL5h7J.js +0 -1
- package/dist/ui/assets/openrouter-B3noN2UV.js +0 -1
- package/dist/ui/assets/provider-store-access-BSELjH0e.js +0 -1
- package/dist/ui/assets/provider-store-access-hpnqQa7b.js +0 -1
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { bundleIndex, bundleToFiles, decodeBundleEnv, encodeBundleEnv, MAX_CONE_CONFIG_BYTES, mergeConeConfig, serializeSecretsEnv, validateConeConfig, validateConeConfigDelta, } from '../../src/cone-config/index.js';
|
|
3
|
+
const base = {
|
|
4
|
+
model: 'anthropic:claude-opus-4-6',
|
|
5
|
+
accounts: [
|
|
6
|
+
{ providerId: 'adobe', kind: 'oauth', accessToken: 'a', tokenExpiresAt: 0 },
|
|
7
|
+
{ providerId: 'anthropic', kind: 'apikey', apiKey: 'k' },
|
|
8
|
+
],
|
|
9
|
+
secrets: [{ name: 'GITHUB_TOKEN', value: 'gt', domains: ['api.github.com', 'github.com'] }],
|
|
10
|
+
};
|
|
11
|
+
describe('validateConeConfig', () => {
|
|
12
|
+
it('accepts a well-formed bundle', () => {
|
|
13
|
+
expect(validateConeConfig(base)).toEqual(base);
|
|
14
|
+
});
|
|
15
|
+
it('rejects an oauth account missing accessToken', () => {
|
|
16
|
+
expect(() => validateConeConfig({ ...base, accounts: [{ providerId: 'x', kind: 'oauth' }] })).toThrow(/accessToken/);
|
|
17
|
+
});
|
|
18
|
+
it('rejects an apikey account missing apiKey', () => {
|
|
19
|
+
expect(() => validateConeConfig({ ...base, accounts: [{ providerId: 'x', kind: 'apikey' }] })).toThrow(/apiKey/);
|
|
20
|
+
});
|
|
21
|
+
it('rejects a secret whose domains is not string[]', () => {
|
|
22
|
+
expect(() => validateConeConfig({ ...base, secrets: [{ name: 'X', value: 'v', domains: 'a,b' }] })).toThrow(/domains/);
|
|
23
|
+
});
|
|
24
|
+
it('rejects an account with a missing/invalid kind', () => {
|
|
25
|
+
expect(() => validateConeConfig({ ...base, accounts: [{ providerId: 'x' }] })).toThrow(/kind required/);
|
|
26
|
+
});
|
|
27
|
+
it('rejects a secret name that is not an env-var identifier', () => {
|
|
28
|
+
expect(() => validateConeConfig({ ...base, secrets: [{ name: 'FOO=BAR', value: 'v', domains: [] }] })).toThrow(/identifier/);
|
|
29
|
+
});
|
|
30
|
+
it('rejects a secret value or domain with a newline (secrets.env is line-based)', () => {
|
|
31
|
+
expect(() => validateConeConfig({ ...base, secrets: [{ name: 'X', value: 'a\nb', domains: [] }] })).toThrow(/single-line/);
|
|
32
|
+
expect(() => validateConeConfig({ ...base, secrets: [{ name: 'X', value: 'v', domains: ['a,b'] }] })).toThrow(/comma-free/);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
describe('validateConeConfigDelta', () => {
|
|
36
|
+
it('accepts a well-formed delta', () => {
|
|
37
|
+
const d = {
|
|
38
|
+
model: 'openai:x',
|
|
39
|
+
upsert: { accounts: [{ providerId: 'openai', kind: 'apikey', apiKey: 'k' }], secrets: [] },
|
|
40
|
+
delete: { providerIds: ['adobe'], secretNames: ['OLD'] },
|
|
41
|
+
};
|
|
42
|
+
expect(validateConeConfigDelta(d)).toEqual(d);
|
|
43
|
+
});
|
|
44
|
+
it('rejects a non-array upsert.accounts', () => {
|
|
45
|
+
expect(() => validateConeConfigDelta({ upsert: { accounts: 'nope' } })).toThrow(/upsert.accounts must be an array/);
|
|
46
|
+
});
|
|
47
|
+
it('rejects a nested secret that would inject a newline', () => {
|
|
48
|
+
expect(() => validateConeConfigDelta({ upsert: { secrets: [{ name: 'X', value: 'a\nb', domains: [] }] } })).toThrow(/single-line/);
|
|
49
|
+
});
|
|
50
|
+
it('rejects a non-string delete.secretNames entry', () => {
|
|
51
|
+
expect(() => validateConeConfigDelta({ delete: { secretNames: [1] } })).toThrow(/secretNames must be string\[\]/);
|
|
52
|
+
});
|
|
53
|
+
it('accepts an empty delta', () => {
|
|
54
|
+
expect(validateConeConfigDelta({})).toEqual({});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
describe('mergeConeConfig', () => {
|
|
58
|
+
it('upserts accounts by providerId and secrets by name, and deletes', () => {
|
|
59
|
+
const merged = mergeConeConfig(base, {
|
|
60
|
+
upsert: {
|
|
61
|
+
accounts: [{ providerId: 'anthropic', kind: 'apikey', apiKey: 'k2' }],
|
|
62
|
+
secrets: [{ name: 'NEW', value: 'n', domains: ['x.com'] }],
|
|
63
|
+
},
|
|
64
|
+
delete: { providerIds: ['adobe'], secretNames: ['GITHUB_TOKEN'] },
|
|
65
|
+
});
|
|
66
|
+
expect(merged.accounts).toEqual([{ providerId: 'anthropic', kind: 'apikey', apiKey: 'k2' }]);
|
|
67
|
+
expect(merged.secrets).toEqual([{ name: 'NEW', value: 'n', domains: ['x.com'] }]);
|
|
68
|
+
expect(merged.model).toBe('anthropic:claude-opus-4-6');
|
|
69
|
+
});
|
|
70
|
+
it('replaces model only when the delta provides one', () => {
|
|
71
|
+
expect(mergeConeConfig(base, { model: 'openai:gpt-x' }).model).toBe('openai:gpt-x');
|
|
72
|
+
expect(mergeConeConfig(base, {}).model).toBe('anthropic:claude-opus-4-6');
|
|
73
|
+
});
|
|
74
|
+
it('handles upsert-only, delete-only, and empty deltas without mutating base', () => {
|
|
75
|
+
const snapshot = JSON.parse(JSON.stringify(base));
|
|
76
|
+
expect(mergeConeConfig(base, { upsert: { secrets: [{ name: 'A', value: 'v', domains: ['x'] }] } })
|
|
77
|
+
.secrets).toHaveLength(2);
|
|
78
|
+
expect(mergeConeConfig(base, { delete: { providerIds: ['anthropic'] } }).accounts).toHaveLength(1);
|
|
79
|
+
expect(mergeConeConfig(base, {}).accounts).toEqual(base.accounts);
|
|
80
|
+
expect(base).toEqual(snapshot); // base not mutated
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
describe('serializeSecretsEnv + bundleToFiles', () => {
|
|
84
|
+
it('emits NAME and NAME_DOMAINS lines', () => {
|
|
85
|
+
expect(serializeSecretsEnv(base.secrets)).toBe('GITHUB_TOKEN=gt\nGITHUB_TOKEN_DOMAINS=api.github.com,github.com\n');
|
|
86
|
+
});
|
|
87
|
+
it('emits empty string for no secrets', () => {
|
|
88
|
+
expect(serializeSecretsEnv([])).toBe('');
|
|
89
|
+
});
|
|
90
|
+
it('splits a bundle into cone-config.json + secrets.env', () => {
|
|
91
|
+
const { coneConfigJson, secretsEnv } = bundleToFiles(base);
|
|
92
|
+
expect(JSON.parse(coneConfigJson)).toEqual({ model: base.model, accounts: base.accounts });
|
|
93
|
+
expect(secretsEnv).toContain('GITHUB_TOKEN=gt');
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
describe('bundleIndex', () => {
|
|
97
|
+
it('produces a names-only index with no values', () => {
|
|
98
|
+
const idx = bundleIndex(base);
|
|
99
|
+
expect(idx).toEqual({
|
|
100
|
+
model: 'anthropic:claude-opus-4-6',
|
|
101
|
+
accountProviderIds: ['adobe', 'anthropic'],
|
|
102
|
+
accountMeta: [
|
|
103
|
+
{ providerId: 'adobe', kind: 'oauth', tokenExpiresAt: 0 },
|
|
104
|
+
{ providerId: 'anthropic', kind: 'apikey', tokenExpiresAt: undefined },
|
|
105
|
+
],
|
|
106
|
+
secretNames: ['GITHUB_TOKEN'],
|
|
107
|
+
});
|
|
108
|
+
expect(JSON.stringify(idx)).not.toContain('gt'); // no secret values leak
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
describe('base64 env round-trip', () => {
|
|
112
|
+
it('round-trips UTF-8 JSON', () => {
|
|
113
|
+
const json = JSON.stringify({ s: 'héllo — 🍦' });
|
|
114
|
+
expect(decodeBundleEnv(encodeBundleEnv(json))).toBe(json);
|
|
115
|
+
});
|
|
116
|
+
it('exposes a positive size cap', () => {
|
|
117
|
+
expect(MAX_CONE_CONFIG_BYTES).toBeGreaterThan(0);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resume-cone-config.test.d.ts","sourceRoot":"","sources":["../../tests/resume-cone-config.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { applyConeConfigDelta } from '../src/operations/resume.js';
|
|
3
|
+
describe('applyConeConfigDelta (read-modify-write of both files)', () => {
|
|
4
|
+
it('merges upserts/deletes, returns new file contents + names index', () => {
|
|
5
|
+
const existingConeConfig = JSON.stringify({
|
|
6
|
+
model: 'adobe:claude-opus-4-6',
|
|
7
|
+
accounts: [{ providerId: 'adobe', kind: 'oauth', accessToken: 'old' }],
|
|
8
|
+
});
|
|
9
|
+
const existingSecretsEnv = 'GITHUB_TOKEN=gt\nGITHUB_TOKEN_DOMAINS=github.com\n';
|
|
10
|
+
const out = applyConeConfigDelta(existingConeConfig, existingSecretsEnv, {
|
|
11
|
+
upsert: {
|
|
12
|
+
accounts: [{ providerId: 'adobe', kind: 'oauth', accessToken: 'fresh' }],
|
|
13
|
+
secrets: [{ name: 'NEW', value: 'n', domains: ['x.com'] }],
|
|
14
|
+
},
|
|
15
|
+
delete: { secretNames: ['GITHUB_TOKEN'] },
|
|
16
|
+
});
|
|
17
|
+
expect(JSON.parse(out.coneConfigJson).accounts[0].accessToken).toBe('fresh');
|
|
18
|
+
expect(out.secretsEnv).toContain('NEW=n');
|
|
19
|
+
expect(out.secretsEnv).not.toContain('GITHUB_TOKEN=gt');
|
|
20
|
+
expect(out.index.secretNames).toEqual(['NEW']);
|
|
21
|
+
});
|
|
22
|
+
it('synthesizes from secrets.env when cone-config.json is missing (pre-feature cone)', () => {
|
|
23
|
+
const out = applyConeConfigDelta(null, 'ADOBE_IMS_TOKEN=abc\nADOBE_IMS_TOKEN_DOMAINS=adobe-llm-proxy.example\n', { upsert: { accounts: [{ providerId: 'adobe', kind: 'oauth', accessToken: 'abc' }] } });
|
|
24
|
+
expect(JSON.parse(out.coneConfigJson).model).toBe('adobe:claude-opus-4-6');
|
|
25
|
+
expect(JSON.parse(out.coneConfigJson).accounts[0].providerId).toBe('adobe');
|
|
26
|
+
});
|
|
27
|
+
it('preserves OTHER flat secrets while refreshing the Adobe bearer (no data loss)', () => {
|
|
28
|
+
const existingConeConfig = JSON.stringify({
|
|
29
|
+
model: 'adobe:claude-opus-4-6',
|
|
30
|
+
accounts: [{ providerId: 'adobe', kind: 'oauth', accessToken: 'old-bearer' }],
|
|
31
|
+
});
|
|
32
|
+
const existingSecretsEnv = 'ADOBE_IMS_TOKEN=old-bearer\nADOBE_IMS_TOKEN_DOMAINS=adobe-llm-proxy\n' +
|
|
33
|
+
'GITHUB_TOKEN=user-pat\nGITHUB_TOKEN_DOMAINS=github.com\n';
|
|
34
|
+
// Mirrors the worker's mergedDelta: refresh Adobe, no user edits.
|
|
35
|
+
const out = applyConeConfigDelta(existingConeConfig, existingSecretsEnv, {
|
|
36
|
+
upsert: {
|
|
37
|
+
accounts: [{ providerId: 'adobe', kind: 'oauth', accessToken: 'fresh-bearer' }],
|
|
38
|
+
secrets: [{ name: 'ADOBE_IMS_TOKEN', value: 'fresh-bearer', domains: ['adobe-llm-proxy'] }],
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
expect(out.secretsEnv).toContain('ADOBE_IMS_TOKEN=fresh-bearer');
|
|
42
|
+
expect(out.secretsEnv).toContain('GITHUB_TOKEN=user-pat'); // PRESERVED
|
|
43
|
+
expect(out.index.secretNames).toContain('GITHUB_TOKEN');
|
|
44
|
+
});
|
|
45
|
+
it('preserves a secret value containing "=" (e.g. base64/JWT) round-trip', () => {
|
|
46
|
+
const out = applyConeConfigDelta(JSON.stringify({ model: 'adobe:claude-opus-4-6', accounts: [] }), 'JWT=aa.bb==.cc\nJWT_DOMAINS=api.example.com\n', {});
|
|
47
|
+
expect(out.secretsEnv).toContain('JWT=aa.bb==.cc');
|
|
48
|
+
});
|
|
49
|
+
it('rejects a merged result with a newline-injecting delta secret', () => {
|
|
50
|
+
expect(() => applyConeConfigDelta(null, '', {
|
|
51
|
+
upsert: { secrets: [{ name: 'X', value: 'a\nEVIL=1', domains: ['x.com'] }] },
|
|
52
|
+
})).toThrow(/single-line/);
|
|
53
|
+
});
|
|
54
|
+
it('surfaces a clear error for a corrupt cone-config.json', () => {
|
|
55
|
+
expect(() => applyConeConfigDelta('{not json', '', {})).toThrow(/corrupt/);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start-cone-config.test.d.ts","sourceRoot":"","sources":["../../tests/start-cone-config.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { startCone } from '../src/operations/start.js';
|
|
3
|
+
import { MemRegistry, makeFakeHandle } from './fixtures/index.js';
|
|
4
|
+
describe('startCone with coneConfigJson', () => {
|
|
5
|
+
it('injects coneConfigJson as SLICC_CONE_CONFIG_B64 env and writes /slicc/cone-config.json', async () => {
|
|
6
|
+
const writes = [];
|
|
7
|
+
let capturedCreateOpts;
|
|
8
|
+
const updatedAt = new Date().toISOString();
|
|
9
|
+
const substrate = {
|
|
10
|
+
id: 'e2b',
|
|
11
|
+
async create(opts) {
|
|
12
|
+
capturedCreateOpts = opts;
|
|
13
|
+
const sandboxId = 'sbx-fake';
|
|
14
|
+
const handle = makeFakeHandle({ sandboxId });
|
|
15
|
+
return {
|
|
16
|
+
sandboxId: handle.sandboxId,
|
|
17
|
+
substrate: handle.substrate,
|
|
18
|
+
pause: handle.pause,
|
|
19
|
+
kill: handle.kill,
|
|
20
|
+
getInfo: handle.getInfo,
|
|
21
|
+
writeFile: async (path, contents) => {
|
|
22
|
+
writes.push({ path, contents });
|
|
23
|
+
},
|
|
24
|
+
readFile: async (path) => {
|
|
25
|
+
if (path === '/tmp/slicc-join.json') {
|
|
26
|
+
return JSON.stringify({
|
|
27
|
+
joinUrl: 'https://w/join/x',
|
|
28
|
+
trayId: 't-1',
|
|
29
|
+
updatedAt,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
throw new Error(`ENOENT ${path}`);
|
|
33
|
+
},
|
|
34
|
+
run: handle.run,
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
async connect() {
|
|
38
|
+
throw new Error('not used');
|
|
39
|
+
},
|
|
40
|
+
async list() {
|
|
41
|
+
return [];
|
|
42
|
+
},
|
|
43
|
+
async extendTimeout() { },
|
|
44
|
+
};
|
|
45
|
+
const registry = new MemRegistry();
|
|
46
|
+
await startCone({ substrate, registry }, {
|
|
47
|
+
envContents: 'GITHUB_TOKEN=gt\nGITHUB_TOKEN_DOMAINS=github.com\n',
|
|
48
|
+
coneConfigJson: '{"model":"anthropic:claude-opus-4-6","accounts":[]}',
|
|
49
|
+
workerBaseUrl: 'https://w',
|
|
50
|
+
sliccVersion: 'web-test',
|
|
51
|
+
});
|
|
52
|
+
// Assert: create opts include both SLICC_SECRETS_ENV_B64 and SLICC_CONE_CONFIG_B64
|
|
53
|
+
expect(capturedCreateOpts).toBeDefined();
|
|
54
|
+
expect(capturedCreateOpts.envVars?.SLICC_SECRETS_ENV_B64).toBeTruthy();
|
|
55
|
+
expect(capturedCreateOpts.envVars?.SLICC_CONE_CONFIG_B64).toBeTruthy();
|
|
56
|
+
// Assert: both files were written
|
|
57
|
+
const secretsWrite = writes.find((w) => w.path === '/slicc/secrets.env');
|
|
58
|
+
const configWrite = writes.find((w) => w.path === '/slicc/cone-config.json');
|
|
59
|
+
expect(secretsWrite).toBeDefined();
|
|
60
|
+
expect(secretsWrite.contents).toContain('GITHUB_TOKEN=gt');
|
|
61
|
+
expect(configWrite).toBeDefined();
|
|
62
|
+
const configJson = JSON.parse(configWrite.contents);
|
|
63
|
+
expect(configJson.model).toBe('anthropic:claude-opus-4-6');
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
* Loopback-only endpoint that hands the hosted-leader page any pre-acquired
|
|
3
|
-
* provider credentials that were uploaded with secrets.env.
|
|
4
|
-
*
|
|
5
|
-
* Currently exposes ADOBE_IMS_TOKEN so the laptop can paste in an IMS bearer
|
|
6
|
-
* once (avoiding OAuth, which can't complete in headless chromium). The
|
|
7
|
-
* webapp's hosted-leader boot calls saveOAuthAccount with the returned token
|
|
8
|
-
* before any LLM call goes out.
|
|
9
|
-
*
|
|
10
|
-
* Same loopback discipline as /api/cloud-status and /api/leader-restart:
|
|
11
|
-
* chromium-on-localhost is the only thing that can hit it; the laptop-side
|
|
12
|
-
* orchestrator talks to the leader through the tray-worker tunnel, not http.
|
|
13
|
-
*/
|
|
1
|
+
import type { Account } from './_cloud_core/src/index.js';
|
|
14
2
|
import type { Express } from 'express';
|
|
15
3
|
import type { SecretStore } from './secrets/types.js';
|
|
16
4
|
export interface HostedBootstrapPayload {
|
|
5
|
+
model?: string;
|
|
6
|
+
accounts?: Account[];
|
|
7
|
+
/** Back-compat: retained so older webapp builds still read the IMS token. */
|
|
17
8
|
adobeImsToken?: string;
|
|
18
9
|
}
|
|
10
|
+
export interface BootstrapSources {
|
|
11
|
+
readConeConfig: () => string | null;
|
|
12
|
+
getLegacyAdobeToken: () => string | undefined;
|
|
13
|
+
}
|
|
14
|
+
export declare function buildHostedBootstrapPayload(sources: BootstrapSources): HostedBootstrapPayload;
|
|
19
15
|
export declare function registerHostedBootstrapEndpoint(app: Express, options: {
|
|
20
16
|
secretStore: SecretStore;
|
|
21
17
|
}): void;
|
|
@@ -1,14 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loopback-only endpoint that hands the hosted-leader page any pre-acquired
|
|
3
|
+
* provider credentials that were uploaded with secrets.env or cone-config.json.
|
|
4
|
+
*
|
|
5
|
+
* The webapp's hosted-leader boot reads {model, accounts} to configure
|
|
6
|
+
* providers and model selection before any LLM call goes out.
|
|
7
|
+
*
|
|
8
|
+
* Back-compat: synthesizes an Adobe oauth account from ADOBE_IMS_TOKEN when
|
|
9
|
+
* cone-config.json is absent. Returns adobeImsToken field for older webapp
|
|
10
|
+
* builds that still expect it.
|
|
11
|
+
*
|
|
12
|
+
* Same loopback discipline as /api/cloud-status and /api/leader-restart:
|
|
13
|
+
* chromium-on-localhost is the only thing that can hit it; the laptop-side
|
|
14
|
+
* orchestrator talks to the leader through the tray-worker tunnel, not http.
|
|
15
|
+
*/
|
|
16
|
+
import { readFileSync } from 'node:fs';
|
|
1
17
|
import { requireLoopback } from './cloud-status.js';
|
|
18
|
+
const CONE_CONFIG_PATH = '/slicc/cone-config.json';
|
|
19
|
+
const DEFAULT_MODEL = 'adobe:claude-opus-4-6';
|
|
20
|
+
export function buildHostedBootstrapPayload(sources) {
|
|
21
|
+
const raw = sources.readConeConfig();
|
|
22
|
+
if (raw) {
|
|
23
|
+
const parsed = JSON.parse(raw);
|
|
24
|
+
return { model: parsed.model, accounts: parsed.accounts ?? [] };
|
|
25
|
+
}
|
|
26
|
+
const legacy = sources.getLegacyAdobeToken();
|
|
27
|
+
if (legacy) {
|
|
28
|
+
return {
|
|
29
|
+
model: DEFAULT_MODEL,
|
|
30
|
+
accounts: [{ providerId: 'adobe', kind: 'oauth', accessToken: legacy }],
|
|
31
|
+
adobeImsToken: legacy,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
2
36
|
export function registerHostedBootstrapEndpoint(app, options) {
|
|
3
37
|
app.get('/api/hosted-bootstrap', requireLoopback, (_req, res) => {
|
|
4
|
-
const payload = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
38
|
+
const payload = buildHostedBootstrapPayload({
|
|
39
|
+
readConeConfig: () => {
|
|
40
|
+
try {
|
|
41
|
+
return readFileSync(CONE_CONFIG_PATH, 'utf-8');
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
// A missing file is the normal pre-feature/back-compat case. Any other
|
|
45
|
+
// error (EACCES, EIO, …) means the config exists but is unreadable —
|
|
46
|
+
// log it so a silent fallback to legacy/empty doesn't hide the cause.
|
|
47
|
+
if (err.code !== 'ENOENT') {
|
|
48
|
+
console.warn('[hosted-bootstrap] failed to read cone-config.json:', err);
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
getLegacyAdobeToken: () => options.secretStore.get('ADOBE_IMS_TOKEN')?.value,
|
|
54
|
+
});
|
|
12
55
|
res.json(payload);
|
|
13
56
|
});
|
|
14
57
|
}
|
|
@@ -36,6 +36,7 @@ import { OauthSecretStore } from './secrets/oauth-secret-store.js';
|
|
|
36
36
|
import { SecretProxyManager } from './secrets/proxy-manager.js';
|
|
37
37
|
import { readOrCreateSessionId } from './secrets/session-id-file.js';
|
|
38
38
|
import { handleDaSignAndForward, handleS3SignAndForward } from './secrets/sign-and-forward.js';
|
|
39
|
+
import { registerSecretsReloadEndpoint } from './secrets-reload-endpoint.js';
|
|
39
40
|
const Dirname = fileURLToPath(new URL('.', import.meta.url));
|
|
40
41
|
const PROJECT_ROOT = resolve(Dirname, '..', '..');
|
|
41
42
|
// ---------------------------------------------------------------------------
|
|
@@ -1033,6 +1034,7 @@ async function main() {
|
|
|
1033
1034
|
if (RUNTIME_FLAGS.hosted) {
|
|
1034
1035
|
registerCloudStatusEndpoint(app, { joinFilePath: '/tmp/slicc-join.json' });
|
|
1035
1036
|
registerHostedBootstrapEndpoint(app, { secretStore });
|
|
1037
|
+
registerSecretsReloadEndpoint(app, { secretProxy });
|
|
1036
1038
|
}
|
|
1037
1039
|
// Fetch proxy — forwards cross-origin requests from the browser to bypass CORS.
|
|
1038
1040
|
// Used by just-bash's curl which calls the browser's fetch() API.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{K as e,L as t,S as n,T as r,U as i,V as a,X as o,Z as s,b as c,et as l,t as u,z as d}from"./kernel-worker-qa_GIQ_O.js";import{getOAuthPageOrigin as f}from"./oauth-service-CWG5aTag.js";var p={proxyEndpoint:`https://adobe-llm-proxy.paolo-moz.workers.dev`,redirectUri:`https://www.sliccy.ai/auth/callback`,extensionRedirectUri:`https://akjjllgokmbgpbdbmafpiefnhidlmbgf.chromiumapp.org/adobe`};function m(e=3e5){let t=0;return{async run(n,r=Date.now()){if(r<t)return null;let i=null;try{i=await n()}catch(e){console.debug(`[silent-renew-backoff] renew threw:`,e instanceof Error?e.message:String(e)),i=null}return t=i?0:r+e,i},inCooldown(e=Date.now()){return e<t}}}const h=Object.assign({"/packages/webapp/providers/adobe-config.json":p})[`/packages/webapp/providers/adobe-config.json`]??{clientId:``,proxyEndpoint:``,scopes:`openid,profile,email`};function g(){let e=n(`adobe`);if(e)return e.replace(/\/$/,``);if(h.proxyEndpoint)return h.proxyEndpoint.replace(/\/$/,``);throw Error(`Adobe proxy endpoint not configured — set it in Settings or adobe-config.json`)}const _=new Map,v=new Map;async function y(e){let t=_.get(e);if(t)return t;try{let t=await fetch(`${e}/v1/config`,{headers:{[F]:`3.26.0`}});if(t.ok){let n=await t.json();return _.set(e,n),n}console.warn(`[adobe] Proxy /v1/config returned ${t.status}, falling back to build-time config`)}catch(e){console.warn(`[adobe] Failed to fetch proxy config:`,e instanceof Error?e.message:String(e))}let n={};return _.set(e,n),n}function b(e){let t=e.clientId||h.clientId;if(!t)throw Error(`Could not determine IMS client ID — proxy /v1/config did not return one and adobe-config.json is empty`);return t}function x(e){return e.scopes||h.scopes}function S(e){return e.imsEnvironment||h.imsEnvironment||`prod`}const C={prod:`https://ims-na1.adobelogin.com`,stg1:`https://ims-na1-stg1.adobelogin.com`};function w(e){return C[e??h.imsEnvironment??`prod`]??C.prod}const T=typeof chrome<`u`&&!!chrome?.runtime?.id;function E(){return c().find(e=>e.providerId===`adobe`)}async function D(e,t){try{let n=await fetch(`${w(t)}/ims/userinfo/v2`,{headers:{Authorization:`Bearer ${e}`}});if(n.ok){let e=await n.json();return{name:e.displayName||e.name||e.email,avatar:e.picture||e.avatar_url}}console.warn(`[adobe] User profile fetch returned ${n.status}, account will have no display name`)}catch(e){console.warn(`[adobe] Failed to fetch user profile:`,e instanceof Error?e.message:String(e))}return{}}function O(e){let t=e.indexOf(`#`);if(t<0)return null;let n=new URLSearchParams(e.slice(t+1)),r=n.get(`access_token`);return r?{accessToken:r,expiresIn:parseInt(n.get(`expires_in`)??`86400`,10)}:null}const k={id:`adobe`,name:`Adobe`,description:`Claude via Adobe — login with your Adobe ID`,requiresApiKey:!1,requiresBaseUrl:!h.proxyEndpoint,baseUrlPlaceholder:`https://your-proxy.example.com`,baseUrlDescription:`Anthropic-compatible proxy endpoint`,isOAuth:!0,defaultModelId:`sonnet`,oauthTokenDomains:[`ims-na1.adobelogin.com`,`ims-na1-stg1.adobelogin.com`,`*.adobelogin.com`,`*.adobe.io`,`firefall.adobe.io`,`admin.hlx.page`,`admin.hlx.live`,`admin.aem.page`,`admin.aem.live`],getModelIds:()=>{let e=e=>{let t={id:e.id,name:e.name??e.id},n=v.get(e.id);return n?.api&&(t.api=n.api),n?.context_window!==void 0&&(t.context_window=n.context_window),n?.max_tokens!==void 0&&(t.max_tokens=n.max_tokens),n?.reasoning!==void 0&&(t.reasoning=n.reasoning),n?.input&&(t.input=n.input),/haiku/i.test(e.id)&&(t.compat={supportsEagerToolInputStreaming:!1}),t};for(let t of W.values())if(t.length){let n=t.map(t=>e({id:t.id,name:t.name??t.id}));try{localStorage.setItem(`slicc-adobe-models`,JSON.stringify(n))}catch{}return n}for(let t of _.values())if(t.models?.length)return t.models.map(e);try{let e=localStorage.getItem(`slicc-adobe-models`);if(e){let t=JSON.parse(e);if(t.length)return t}}catch{}return[{id:`claude-sonnet-4-6`,name:`Claude Sonnet 4.6`}]},onOAuthLogin:async(e,t,n)=>{let i=g(),a=await y(i),o=b(a),s=x(a),c=S(a),l=T?null:await f(),u=T?h.extensionRedirectUri??`https://${chrome.runtime.id}.chromiumapp.org/`:h.redirectUri??`${l.origin}/auth/callback`,d=T?void 0:btoa(JSON.stringify({port:parseInt(new URL(l.href).port||`5710`,10),path:`/auth/callback`,nonce:crypto.randomUUID()})),p=d?JSON.parse(atob(d)).nonce:null,m=new URLSearchParams({client_id:o,scope:s,response_type:`token`,redirect_uri:u});d&&m.set(`state`,d),n?.forceReauth&&m.set(`prompt`,`login`);let _=await e(`${w(c)}/ims/authorize/v2?${m}`);if(!_)return;if(p&&_)try{if(new URL(_).searchParams.get(`nonce`)!==p){console.error(`[adobe] OAuth nonce mismatch — possible CSRF`);return}}catch(e){console.warn(`[adobe] Nonce check skipped (URL parse failed):`,e instanceof Error?e.message:String(e))}let v=O(_);if(!v){console.error(`[adobe] Could not extract token from redirect URL`);return}let C=await D(v.accessToken,c);await r({providerId:`adobe`,accessToken:v.accessToken,tokenExpiresAt:Date.now()+v.expiresIn*1e3,userName:C.name,userAvatar:C.avatar,baseUrl:h.proxyEndpoint?void 0:i}),await G().catch(e=>console.warn(`[adobe] Failed to fetch models after login:`,e instanceof Error?e.message:String(e))),t()},onOAuthLogout:async()=>{let e=E();if(e?.accessToken)try{let t=_.values().next().value??{},n=t.clientId||h.clientId,r=S(t);if(n){let t=await fetch(`${w(r)}/ims/revoke`,{method:`POST`,headers:{"Content-Type":`application/x-www-form-urlencoded`},body:new URLSearchParams({token:e.accessToken,token_type_hint:`access_token`,client_id:n})});t.ok||console.warn(`[adobe] Token revocation returned ${t.status}, token may still be valid server-side`)}}catch(e){console.warn(`[adobe] Failed to revoke token:`,e instanceof Error?e.message:String(e))}await r({providerId:`adobe`,accessToken:``})},onSilentRenew:async()=>E()?.accessToken?P():null};let A=null;const j=m();async function M(){let e=E();if(!e?.accessToken)throw Error(`Not logged in to Adobe — please log in first`);if((e.tokenExpiresAt??0)-Date.now()>6e4)return e.accessToken;console.log(`[adobe] Token expired or expiring soon, attempting silent renewal...`);let t=await j.run(()=>P());if(t)return t;let n=E();if((n?.tokenExpiresAt??0)-Date.now()>0&&n?.accessToken)return n.accessToken;throw Error(`Adobe session expired — please log in again`)}function N(){let e=E();return e?.tokenExpiresAt?Date.now()>e.tokenExpiresAt-6e4:!0}async function P(){return typeof window>`u`?null:A||(A=(async()=>{try{let e=g(),t=await y(e),n=b(t),i=x(t),a=S(t),o=T?h.extensionRedirectUri??`https://${chrome.runtime.id}.chromiumapp.org/`:h.redirectUri??`${window.location.origin}/auth/callback`,s=T?void 0:btoa(JSON.stringify({port:parseInt(new URL(window.location.href).port||`5710`,10),path:`/auth/callback`,nonce:crypto.randomUUID()})),c=s?JSON.parse(atob(s)).nonce:null,l=new URLSearchParams({client_id:n,scope:i,response_type:`token`,redirect_uri:o,prompt:`none`});s&&l.set(`state`,s);let u=`${w(a)}/ims/authorize/v2?${l}`,{createOAuthLauncher:d}=await import(`./oauth-service-CWG5aTag.js`),f=await d()(u,{interactive:!1});if(!f)return null;if(c&&f)try{if(new URL(f).searchParams.get(`nonce`)!==c)return console.error(`[adobe] OAuth nonce mismatch — possible CSRF`),null}catch(e){console.warn(`[adobe] Nonce check skipped (URL parse failed):`,e instanceof Error?e.message:String(e))}let p=O(f);if(!p)return null;let m=E();return await r({providerId:`adobe`,accessToken:p.accessToken,tokenExpiresAt:Date.now()+p.expiresIn*1e3,userName:m?.userName,userAvatar:m?.userAvatar,baseUrl:h.proxyEndpoint?void 0:e}),console.log(`[adobe] Token renewed silently`),await G().catch(e=>console.warn(`[adobe] Failed to refresh models after silent renewal:`,e instanceof Error?e.message:String(e))),p.accessToken}catch(e){return console.warn(`[adobe] Silent renewal error:`,e instanceof Error?e.message:String(e)),null}finally{A=null}})(),A)}const F=`X-Slicc-Version`;function I(e){let t={};if(e.headers)for(let[n,r]of Object.entries(e.headers))n.toLowerCase()!==`x-slicc-version`&&(t[n]=r);return t[F]=`3.26.0`,{...e,headers:t}}const L=new Set;function R(e,t){if(e.headers){for(let t of Object.keys(e.headers))if(t.toLowerCase()===`x-session-id`)return e}return L.has(t)||(L.add(t),console.warn(`[adobe] Missing X-Session-Id from ${t} — using daily fallback. Attach an X-Session-Id header at the call site (see scoop-context.ts streamWithSessionId or docs/pitfalls.md).`)),{...e,headers:{...e.headers??{},"X-Session-Id":u(`adobe-provider-fallback`)}}}function z(){L.clear()}function B(e,t){return{type:`error`,reason:`error`,error:{role:`assistant`,content:[],api:`adobe-anthropic`,provider:`adobe`,model:e.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:`error`,errorMessage:t instanceof Error?t.message:String(t),timestamp:Date.now()}}}const V=(n,r,i={})=>{let a=e();return(async()=>{try{let e=await M();if(String(n.api).includes(`openai`)){let t=d({...n,baseUrl:`${g()}/v1`,api:`openai-completions`,compat:{...n.compat,supportsStore:!1,supportsDeveloperRole:!1}},r,I(R({...i,apiKey:e},`streamAdobe[openai]`)));for await(let e of t)a.push(e)}else{let o=t({...n,baseUrl:g(),api:`anthropic-messages`},r,I(R({...i,apiKey:e},`streamAdobe[anthropic]`)));for await(let e of o)a.push(e)}a.end()}catch(e){console.error(`[adobe] Stream error:`,e instanceof Error?e.message:String(e)),a.push(B(n,e)),a.end()}})(),a},H=(t,n,r)=>{let o=e();return(async()=>{try{let e=await M();if(String(t.api).includes(`openai`)){let a=i({...t,baseUrl:`${g()}/v1`,api:`openai-completions`,compat:{...t.compat,supportsStore:!1,supportsDeveloperRole:!1}},n,I(R({...r,apiKey:e},`streamSimpleAdobe[openai]`)));for await(let e of a)o.push(e)}else{let i=a({...t,baseUrl:g(),api:`anthropic-messages`},n,I(R({...r,apiKey:e},`streamSimpleAdobe[anthropic]`)));for await(let e of i)o.push(e)}o.end()}catch(e){console.error(`[adobe] Stream error:`,e instanceof Error?e.message:String(e)),o.push(B(t,e)),o.end()}})(),o};async function U(){try{let e=await M(),t=g(),n=await fetch(`${t}/v1/models`,{headers:{Authorization:`Bearer ${e}`,[F]:`3.26.0`}});if(n.ok){let e=await n.json();if(e.data?.length){for(let t of e.data){let e={id:t.id,name:t.name};t.api!==void 0&&(e.api=t.api),t.context_window!==void 0&&(e.context_window=t.context_window),t.max_tokens!==void 0&&(e.max_tokens=t.max_tokens),t.reasoning!==void 0&&(e.reasoning=t.reasoning),t.input!==void 0&&(e.input=t.input),v.set(t.id,e)}let n=new Map;for(let e of s())try{for(let t of o(e))n.set(t.id,t)}catch{}return e.data.map(e=>{let r=n.get(e.id),i=`adobe-${e.api===`openai`?`openai`:`anthropic`}`;return r?{...r,provider:`adobe`,api:i}:{id:e.id,name:e.name??e.id,provider:`adobe`,api:i,baseUrl:t,contextWindow:2e5,maxTokens:16384,input:[`text`,`image`],cost:{input:0,output:0,cacheRead:0,cacheWrite:0},inputCost:0,outputCost:0,cacheReadCost:0,cacheWriteCost:0,reasoning:!0}})}}else console.warn(`[adobe] Proxy /v1/models returned ${n.status}, falling back to Anthropic models`)}catch(e){console.warn(`[adobe] Failed to fetch proxy models:`,e instanceof Error?e.message:String(e))}return o(`anthropic`).map(e=>({...e,provider:`adobe`,api:`adobe-anthropic`}))}const W=new Map;async function G(){let e=g(),t=W.get(e);if(t)return t;let n=await U();return W.set(e,n),n}function K(){l({api:`adobe-anthropic`,stream:V,streamSimple:H}),l({api:`adobe-openai`,stream:V,streamSimple:H})}export{z as __resetAdobeSessionIdWarningCacheForTests,k as config,G as getAdobeModels,M as getValidAccessToken,N as isTokenExpired,K as register};
|
|
1
|
+
import{K as e,L as t,S as n,T as r,U as i,V as a,X as o,Z as s,b as c,et as l,t as u,z as d}from"./kernel-worker-BXAud9Z1.js";import{getOAuthPageOrigin as f}from"./oauth-service-Br_yPLR6.js";var p={proxyEndpoint:`https://adobe-llm-proxy.paolo-moz.workers.dev`,redirectUri:`https://www.sliccy.ai/auth/callback`,extensionRedirectUri:`https://akjjllgokmbgpbdbmafpiefnhidlmbgf.chromiumapp.org/adobe`};function m(e=3e5){let t=0;return{async run(n,r=Date.now()){if(r<t)return null;let i=null;try{i=await n()}catch(e){console.debug(`[silent-renew-backoff] renew threw:`,e instanceof Error?e.message:String(e)),i=null}return t=i?0:r+e,i},inCooldown(e=Date.now()){return e<t}}}const h=Object.assign({"/packages/webapp/providers/adobe-config.json":p})[`/packages/webapp/providers/adobe-config.json`]??{clientId:``,proxyEndpoint:``,scopes:`openid,profile,email`};function g(){let e=n(`adobe`);if(e)return e.replace(/\/$/,``);if(h.proxyEndpoint)return h.proxyEndpoint.replace(/\/$/,``);throw Error(`Adobe proxy endpoint not configured — set it in Settings or adobe-config.json`)}const _=new Map,v=new Map;async function y(e){let t=_.get(e);if(t)return t;try{let t=await fetch(`${e}/v1/config`,{headers:{[F]:`3.27.0`}});if(t.ok){let n=await t.json();return _.set(e,n),n}console.warn(`[adobe] Proxy /v1/config returned ${t.status}, falling back to build-time config`)}catch(e){console.warn(`[adobe] Failed to fetch proxy config:`,e instanceof Error?e.message:String(e))}let n={};return _.set(e,n),n}function b(e){let t=e.clientId||h.clientId;if(!t)throw Error(`Could not determine IMS client ID — proxy /v1/config did not return one and adobe-config.json is empty`);return t}function x(e){return e.scopes||h.scopes}function S(e){return e.imsEnvironment||h.imsEnvironment||`prod`}const C={prod:`https://ims-na1.adobelogin.com`,stg1:`https://ims-na1-stg1.adobelogin.com`};function w(e){return C[e??h.imsEnvironment??`prod`]??C.prod}const T=typeof chrome<`u`&&!!chrome?.runtime?.id;function E(){return c().find(e=>e.providerId===`adobe`)}async function D(e,t){try{let n=await fetch(`${w(t)}/ims/userinfo/v2`,{headers:{Authorization:`Bearer ${e}`}});if(n.ok){let e=await n.json();return{name:e.displayName||e.name||e.email,avatar:e.picture||e.avatar_url}}console.warn(`[adobe] User profile fetch returned ${n.status}, account will have no display name`)}catch(e){console.warn(`[adobe] Failed to fetch user profile:`,e instanceof Error?e.message:String(e))}return{}}function O(e){let t=e.indexOf(`#`);if(t<0)return null;let n=new URLSearchParams(e.slice(t+1)),r=n.get(`access_token`);return r?{accessToken:r,expiresIn:parseInt(n.get(`expires_in`)??`86400`,10)}:null}const k={id:`adobe`,name:`Adobe`,description:`Claude via Adobe — login with your Adobe ID`,requiresApiKey:!1,requiresBaseUrl:!h.proxyEndpoint,baseUrlPlaceholder:`https://your-proxy.example.com`,baseUrlDescription:`Anthropic-compatible proxy endpoint`,isOAuth:!0,defaultModelId:`sonnet`,oauthTokenDomains:[`ims-na1.adobelogin.com`,`ims-na1-stg1.adobelogin.com`,`*.adobelogin.com`,`*.adobe.io`,`firefall.adobe.io`,`admin.hlx.page`,`admin.hlx.live`,`admin.aem.page`,`admin.aem.live`],getModelIds:()=>{let e=e=>{let t={id:e.id,name:e.name??e.id},n=v.get(e.id);return n?.api&&(t.api=n.api),n?.context_window!==void 0&&(t.context_window=n.context_window),n?.max_tokens!==void 0&&(t.max_tokens=n.max_tokens),n?.reasoning!==void 0&&(t.reasoning=n.reasoning),n?.input&&(t.input=n.input),/haiku/i.test(e.id)&&(t.compat={supportsEagerToolInputStreaming:!1}),t};for(let t of W.values())if(t.length){let n=t.map(t=>e({id:t.id,name:t.name??t.id}));try{localStorage.setItem(`slicc-adobe-models`,JSON.stringify(n))}catch{}return n}for(let t of _.values())if(t.models?.length)return t.models.map(e);try{let e=localStorage.getItem(`slicc-adobe-models`);if(e){let t=JSON.parse(e);if(t.length)return t}}catch{}return[{id:`claude-sonnet-4-6`,name:`Claude Sonnet 4.6`}]},onOAuthLogin:async(e,t,n)=>{let i=g(),a=await y(i),o=b(a),s=x(a),c=S(a),l=T?null:await f(),u=T?h.extensionRedirectUri??`https://${chrome.runtime.id}.chromiumapp.org/`:h.redirectUri??`${l.origin}/auth/callback`,d=T?void 0:btoa(JSON.stringify({port:parseInt(new URL(l.href).port||`5710`,10),path:`/auth/callback`,nonce:crypto.randomUUID()})),p=d?JSON.parse(atob(d)).nonce:null,m=new URLSearchParams({client_id:o,scope:s,response_type:`token`,redirect_uri:u});d&&m.set(`state`,d),n?.forceReauth&&m.set(`prompt`,`login`);let _=await e(`${w(c)}/ims/authorize/v2?${m}`);if(!_)return;if(p&&_)try{if(new URL(_).searchParams.get(`nonce`)!==p){console.error(`[adobe] OAuth nonce mismatch — possible CSRF`);return}}catch(e){console.warn(`[adobe] Nonce check skipped (URL parse failed):`,e instanceof Error?e.message:String(e))}let v=O(_);if(!v){console.error(`[adobe] Could not extract token from redirect URL`);return}let C=await D(v.accessToken,c);await r({providerId:`adobe`,accessToken:v.accessToken,tokenExpiresAt:Date.now()+v.expiresIn*1e3,userName:C.name,userAvatar:C.avatar,baseUrl:h.proxyEndpoint?void 0:i}),await G().catch(e=>console.warn(`[adobe] Failed to fetch models after login:`,e instanceof Error?e.message:String(e))),t()},onOAuthLogout:async()=>{let e=E();if(e?.accessToken)try{let t=_.values().next().value??{},n=t.clientId||h.clientId,r=S(t);if(n){let t=await fetch(`${w(r)}/ims/revoke`,{method:`POST`,headers:{"Content-Type":`application/x-www-form-urlencoded`},body:new URLSearchParams({token:e.accessToken,token_type_hint:`access_token`,client_id:n})});t.ok||console.warn(`[adobe] Token revocation returned ${t.status}, token may still be valid server-side`)}}catch(e){console.warn(`[adobe] Failed to revoke token:`,e instanceof Error?e.message:String(e))}await r({providerId:`adobe`,accessToken:``})},onSilentRenew:async()=>E()?.accessToken?P():null};let A=null;const j=m();async function M(){let e=E();if(!e?.accessToken)throw Error(`Not logged in to Adobe — please log in first`);if((e.tokenExpiresAt??0)-Date.now()>6e4)return e.accessToken;console.log(`[adobe] Token expired or expiring soon, attempting silent renewal...`);let t=await j.run(()=>P());if(t)return t;let n=E();if((n?.tokenExpiresAt??0)-Date.now()>0&&n?.accessToken)return n.accessToken;throw Error(`Adobe session expired — please log in again`)}function N(){let e=E();return e?.tokenExpiresAt?Date.now()>e.tokenExpiresAt-6e4:!0}async function P(){return typeof window>`u`?null:A||(A=(async()=>{try{let e=g(),t=await y(e),n=b(t),i=x(t),a=S(t),o=T?h.extensionRedirectUri??`https://${chrome.runtime.id}.chromiumapp.org/`:h.redirectUri??`${window.location.origin}/auth/callback`,s=T?void 0:btoa(JSON.stringify({port:parseInt(new URL(window.location.href).port||`5710`,10),path:`/auth/callback`,nonce:crypto.randomUUID()})),c=s?JSON.parse(atob(s)).nonce:null,l=new URLSearchParams({client_id:n,scope:i,response_type:`token`,redirect_uri:o,prompt:`none`});s&&l.set(`state`,s);let u=`${w(a)}/ims/authorize/v2?${l}`,{createOAuthLauncher:d}=await import(`./oauth-service-Br_yPLR6.js`),f=await d()(u,{interactive:!1});if(!f)return null;if(c&&f)try{if(new URL(f).searchParams.get(`nonce`)!==c)return console.error(`[adobe] OAuth nonce mismatch — possible CSRF`),null}catch(e){console.warn(`[adobe] Nonce check skipped (URL parse failed):`,e instanceof Error?e.message:String(e))}let p=O(f);if(!p)return null;let m=E();return await r({providerId:`adobe`,accessToken:p.accessToken,tokenExpiresAt:Date.now()+p.expiresIn*1e3,userName:m?.userName,userAvatar:m?.userAvatar,baseUrl:h.proxyEndpoint?void 0:e}),console.log(`[adobe] Token renewed silently`),await G().catch(e=>console.warn(`[adobe] Failed to refresh models after silent renewal:`,e instanceof Error?e.message:String(e))),p.accessToken}catch(e){return console.warn(`[adobe] Silent renewal error:`,e instanceof Error?e.message:String(e)),null}finally{A=null}})(),A)}const F=`X-Slicc-Version`;function I(e){let t={};if(e.headers)for(let[n,r]of Object.entries(e.headers))n.toLowerCase()!==`x-slicc-version`&&(t[n]=r);return t[F]=`3.27.0`,{...e,headers:t}}const L=new Set;function R(e,t){if(e.headers){for(let t of Object.keys(e.headers))if(t.toLowerCase()===`x-session-id`)return e}return L.has(t)||(L.add(t),console.warn(`[adobe] Missing X-Session-Id from ${t} — using daily fallback. Attach an X-Session-Id header at the call site (see scoop-context.ts streamWithSessionId or docs/pitfalls.md).`)),{...e,headers:{...e.headers??{},"X-Session-Id":u(`adobe-provider-fallback`)}}}function z(){L.clear()}function B(e,t){return{type:`error`,reason:`error`,error:{role:`assistant`,content:[],api:`adobe-anthropic`,provider:`adobe`,model:e.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:`error`,errorMessage:t instanceof Error?t.message:String(t),timestamp:Date.now()}}}const V=(n,r,i={})=>{let a=e();return(async()=>{try{let e=await M();if(String(n.api).includes(`openai`)){let t=d({...n,baseUrl:`${g()}/v1`,api:`openai-completions`,compat:{...n.compat,supportsStore:!1,supportsDeveloperRole:!1}},r,I(R({...i,apiKey:e},`streamAdobe[openai]`)));for await(let e of t)a.push(e)}else{let o=t({...n,baseUrl:g(),api:`anthropic-messages`},r,I(R({...i,apiKey:e},`streamAdobe[anthropic]`)));for await(let e of o)a.push(e)}a.end()}catch(e){console.error(`[adobe] Stream error:`,e instanceof Error?e.message:String(e)),a.push(B(n,e)),a.end()}})(),a},H=(t,n,r)=>{let o=e();return(async()=>{try{let e=await M();if(String(t.api).includes(`openai`)){let a=i({...t,baseUrl:`${g()}/v1`,api:`openai-completions`,compat:{...t.compat,supportsStore:!1,supportsDeveloperRole:!1}},n,I(R({...r,apiKey:e},`streamSimpleAdobe[openai]`)));for await(let e of a)o.push(e)}else{let i=a({...t,baseUrl:g(),api:`anthropic-messages`},n,I(R({...r,apiKey:e},`streamSimpleAdobe[anthropic]`)));for await(let e of i)o.push(e)}o.end()}catch(e){console.error(`[adobe] Stream error:`,e instanceof Error?e.message:String(e)),o.push(B(t,e)),o.end()}})(),o};async function U(){try{let e=await M(),t=g(),n=await fetch(`${t}/v1/models`,{headers:{Authorization:`Bearer ${e}`,[F]:`3.27.0`}});if(n.ok){let e=await n.json();if(e.data?.length){for(let t of e.data){let e={id:t.id,name:t.name};t.api!==void 0&&(e.api=t.api),t.context_window!==void 0&&(e.context_window=t.context_window),t.max_tokens!==void 0&&(e.max_tokens=t.max_tokens),t.reasoning!==void 0&&(e.reasoning=t.reasoning),t.input!==void 0&&(e.input=t.input),v.set(t.id,e)}let n=new Map;for(let e of s())try{for(let t of o(e))n.set(t.id,t)}catch{}return e.data.map(e=>{let r=n.get(e.id),i=`adobe-${e.api===`openai`?`openai`:`anthropic`}`;return r?{...r,provider:`adobe`,api:i}:{id:e.id,name:e.name??e.id,provider:`adobe`,api:i,baseUrl:t,contextWindow:2e5,maxTokens:16384,input:[`text`,`image`],cost:{input:0,output:0,cacheRead:0,cacheWrite:0},inputCost:0,outputCost:0,cacheReadCost:0,cacheWriteCost:0,reasoning:!0}})}}else console.warn(`[adobe] Proxy /v1/models returned ${n.status}, falling back to Anthropic models`)}catch(e){console.warn(`[adobe] Failed to fetch proxy models:`,e instanceof Error?e.message:String(e))}return o(`anthropic`).map(e=>({...e,provider:`adobe`,api:`adobe-anthropic`}))}const W=new Map;async function G(){let e=g(),t=W.get(e);if(t)return t;let n=await U();return W.set(e,n),n}function K(){l({api:`adobe-anthropic`,stream:V,streamSimple:H}),l({api:`adobe-openai`,stream:V,streamSimple:H})}export{z as __resetAdobeSessionIdWarningCacheForTests,k as config,G as getAdobeModels,M as getValidAccessToken,N as isTokenExpired,K as register};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/oauth-service-BWOcUJw9.js","assets/main-B019n563.js","assets/modulepreload-polyfill-Dezn_h7o.js","assets/main-BxXY3xQw.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{H as e,J as t,K as n,W as r,Z as i,at as a,f as o,it as s,n as c,nt as l,r as u,s as d,tt as f}from"./main-B019n563.js";import{getOAuthPageOrigin as p}from"./oauth-service-BWOcUJw9.js";var m={proxyEndpoint:`https://adobe-llm-proxy.paolo-moz.workers.dev`,redirectUri:`https://www.sliccy.ai/auth/callback`,extensionRedirectUri:`https://akjjllgokmbgpbdbmafpiefnhidlmbgf.chromiumapp.org/adobe`},h=5*6e4;function g(e=h){let t=0;return{async run(n,r=Date.now()){if(r<t)return null;let i=null;try{i=await n()}catch(e){console.debug(`[silent-renew-backoff] renew threw:`,e instanceof Error?e.message:String(e)),i=null}return t=i?0:r+e,i},inCooldown(e=Date.now()){return e<t}}}var _=Object.assign({"/packages/webapp/providers/adobe-config.json":m})[`/packages/webapp/providers/adobe-config.json`]??{clientId:``,proxyEndpoint:``,scopes:`openid,profile,email`};function v(){let e=d(`adobe`);if(e)return e.replace(/\/$/,``);if(_.proxyEndpoint)return _.proxyEndpoint.replace(/\/$/,``);throw Error(`Adobe proxy endpoint not configured — set it in Settings or adobe-config.json`)}var y=new Map,b=new Map;async function x(e){let t=y.get(e);if(t)return t;try{let t=await fetch(`${e}/v1/config`,{headers:{[L]:`3.27.0`}});if(t.ok){let n=await t.json();return y.set(e,n),n}console.warn(`[adobe] Proxy /v1/config returned ${t.status}, falling back to build-time config`)}catch(e){console.warn(`[adobe] Failed to fetch proxy config:`,e instanceof Error?e.message:String(e))}let n={};return y.set(e,n),n}function S(e){let t=e.clientId||_.clientId;if(!t)throw Error(`Could not determine IMS client ID — proxy /v1/config did not return one and adobe-config.json is empty`);return t}function C(e){return e.scopes||_.scopes}function w(e){return e.imsEnvironment||_.imsEnvironment||`prod`}var T={prod:`https://ims-na1.adobelogin.com`,stg1:`https://ims-na1-stg1.adobelogin.com`};function E(e){return T[e??_.imsEnvironment??`prod`]??T.prod}var D=typeof chrome<`u`&&!!chrome?.runtime?.id;function O(){return u().find(e=>e.providerId===`adobe`)}async function k(e,t){try{let n=await fetch(`${E(t)}/ims/userinfo/v2`,{headers:{Authorization:`Bearer ${e}`}});if(n.ok){let e=await n.json();return{name:e.displayName||e.name||e.email,avatar:e.picture||e.avatar_url}}console.warn(`[adobe] User profile fetch returned ${n.status}, account will have no display name`)}catch(e){console.warn(`[adobe] Failed to fetch user profile:`,e instanceof Error?e.message:String(e))}return{}}function A(e){let t=e.indexOf(`#`);if(t<0)return null;let n=new URLSearchParams(e.slice(t+1)),r=n.get(`access_token`);return r?{accessToken:r,expiresIn:parseInt(n.get(`expires_in`)??`86400`,10)}:null}var j={id:`adobe`,name:`Adobe`,description:`Claude via Adobe — login with your Adobe ID`,requiresApiKey:!1,requiresBaseUrl:!_.proxyEndpoint,baseUrlPlaceholder:`https://your-proxy.example.com`,baseUrlDescription:`Anthropic-compatible proxy endpoint`,isOAuth:!0,defaultModelId:`sonnet`,oauthTokenDomains:[`ims-na1.adobelogin.com`,`ims-na1-stg1.adobelogin.com`,`*.adobelogin.com`,`*.adobe.io`,`firefall.adobe.io`,`admin.hlx.page`,`admin.hlx.live`,`admin.aem.page`,`admin.aem.live`],getModelIds:()=>{let e=e=>{let t={id:e.id,name:e.name??e.id},n=b.get(e.id);return n?.api&&(t.api=n.api),n?.context_window!==void 0&&(t.context_window=n.context_window),n?.max_tokens!==void 0&&(t.max_tokens=n.max_tokens),n?.reasoning!==void 0&&(t.reasoning=n.reasoning),n?.input&&(t.input=n.input),/haiku/i.test(e.id)&&(t.compat={supportsEagerToolInputStreaming:!1}),t};for(let t of q.values())if(t.length){let n=t.map(t=>e({id:t.id,name:t.name??t.id}));try{localStorage.setItem(`slicc-adobe-models`,JSON.stringify(n))}catch{}return n}for(let t of y.values())if(t.models?.length)return t.models.map(e);try{let e=localStorage.getItem(`slicc-adobe-models`);if(e){let t=JSON.parse(e);if(t.length)return t}}catch{}return[{id:`claude-sonnet-4-6`,name:`Claude Sonnet 4.6`}]},onOAuthLogin:async(e,t,n)=>{let r=v(),i=await x(r),a=S(i),s=C(i),c=w(i),l=D?null:await p(),u=D?_.extensionRedirectUri??`https://${chrome.runtime.id}.chromiumapp.org/`:_.redirectUri??`${l.origin}/auth/callback`,d=D?void 0:btoa(JSON.stringify({port:parseInt(new URL(l.href).port||`5710`,10),path:`/auth/callback`,nonce:crypto.randomUUID()})),f=d?JSON.parse(atob(d)).nonce:null,m=new URLSearchParams({client_id:a,scope:s,response_type:`token`,redirect_uri:u});d&&m.set(`state`,d),n?.forceReauth&&m.set(`prompt`,`login`);let h=await e(`${E(c)}/ims/authorize/v2?${m}`);if(!h)return;if(f&&h)try{if(new URL(h).searchParams.get(`nonce`)!==f){console.error(`[adobe] OAuth nonce mismatch — possible CSRF`);return}}catch(e){console.warn(`[adobe] Nonce check skipped (URL parse failed):`,e instanceof Error?e.message:String(e))}let g=A(h);if(!g){console.error(`[adobe] Could not extract token from redirect URL`);return}let y=await k(g.accessToken,c);await o({providerId:`adobe`,accessToken:g.accessToken,tokenExpiresAt:Date.now()+g.expiresIn*1e3,userName:y.name,userAvatar:y.avatar,baseUrl:_.proxyEndpoint?void 0:r}),await J().catch(e=>console.warn(`[adobe] Failed to fetch models after login:`,e instanceof Error?e.message:String(e))),t()},onOAuthLogout:async()=>{let e=O();if(e?.accessToken)try{let t=y.values().next().value??{},n=t.clientId||_.clientId,r=w(t);if(n){let t=await fetch(`${E(r)}/ims/revoke`,{method:`POST`,headers:{"Content-Type":`application/x-www-form-urlencoded`},body:new URLSearchParams({token:e.accessToken,token_type_hint:`access_token`,client_id:n})});t.ok||console.warn(`[adobe] Token revocation returned ${t.status}, token may still be valid server-side`)}}catch(e){console.warn(`[adobe] Failed to revoke token:`,e instanceof Error?e.message:String(e))}await o({providerId:`adobe`,accessToken:``})},onSilentRenew:async()=>O()?.accessToken?I():null},M=null,N=g();async function P(){let e=O();if(!e?.accessToken)throw Error(`Not logged in to Adobe — please log in first`);if((e.tokenExpiresAt??0)-Date.now()>6e4)return e.accessToken;console.log(`[adobe] Token expired or expiring soon, attempting silent renewal...`);let t=await N.run(()=>I());if(t)return t;let n=O();if((n?.tokenExpiresAt??0)-Date.now()>0&&n?.accessToken)return n.accessToken;throw Error(`Adobe session expired — please log in again`)}function F(){let e=O();return e?.tokenExpiresAt?Date.now()>e.tokenExpiresAt-6e4:!0}async function I(){return typeof window>`u`?null:M||(M=(async()=>{try{let e=v(),t=await x(e),n=S(t),r=C(t),i=w(t),a=D?_.extensionRedirectUri??`https://${chrome.runtime.id}.chromiumapp.org/`:_.redirectUri??`${window.location.origin}/auth/callback`,c=D?void 0:btoa(JSON.stringify({port:parseInt(new URL(window.location.href).port||`5710`,10),path:`/auth/callback`,nonce:crypto.randomUUID()})),l=c?JSON.parse(atob(c)).nonce:null,u=new URLSearchParams({client_id:n,scope:r,response_type:`token`,redirect_uri:a,prompt:`none`});c&&u.set(`state`,c);let d=`${E(i)}/ims/authorize/v2?${u}`,{createOAuthLauncher:f}=await s(async()=>{let{createOAuthLauncher:e}=await import(`./oauth-service-BWOcUJw9.js`);return{createOAuthLauncher:e}},__vite__mapDeps([0,1,2,3])),p=await f()(d,{interactive:!1});if(!p)return null;if(l&&p)try{if(new URL(p).searchParams.get(`nonce`)!==l)return console.error(`[adobe] OAuth nonce mismatch — possible CSRF`),null}catch(e){console.warn(`[adobe] Nonce check skipped (URL parse failed):`,e instanceof Error?e.message:String(e))}let m=A(p);if(!m)return null;let h=O();return await o({providerId:`adobe`,accessToken:m.accessToken,tokenExpiresAt:Date.now()+m.expiresIn*1e3,userName:h?.userName,userAvatar:h?.userAvatar,baseUrl:_.proxyEndpoint?void 0:e}),console.log(`[adobe] Token renewed silently`),await J().catch(e=>console.warn(`[adobe] Failed to refresh models after silent renewal:`,e instanceof Error?e.message:String(e))),m.accessToken}catch(e){return console.warn(`[adobe] Silent renewal error:`,e instanceof Error?e.message:String(e)),null}finally{M=null}})(),M)}var L=`X-Slicc-Version`;function R(e){let t={},n=L.toLowerCase();if(e.headers)for(let[r,i]of Object.entries(e.headers))r.toLowerCase()!==n&&(t[r]=i);return t[L]=`3.27.0`,{...e,headers:t}}var z=`adobe-provider-fallback`,B=new Set;function V(e,t){if(e.headers){for(let t of Object.keys(e.headers))if(t.toLowerCase()===`x-session-id`)return e}return B.has(t)||(B.add(t),console.warn(`[adobe] Missing X-Session-Id from ${t} — using daily fallback. Attach an X-Session-Id header at the call site (see scoop-context.ts streamWithSessionId or docs/pitfalls.md).`)),{...e,headers:{...e.headers??{},"X-Session-Id":c(z)}}}function H(){B.clear()}function U(e,t){return{type:`error`,reason:`error`,error:{role:`assistant`,content:[],api:`adobe-anthropic`,provider:`adobe`,model:e.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:`error`,errorMessage:t instanceof Error?t.message:String(t),timestamp:Date.now()}}}var W=(t,n,a={})=>{let o=i();return(async()=>{try{let i=await P();if(String(t.api).includes(`openai`)){let e=r({...t,baseUrl:`${v()}/v1`,api:`openai-completions`,compat:{...t.compat,supportsStore:!1,supportsDeveloperRole:!1}},n,R(V({...a,apiKey:i},`streamAdobe[openai]`)));for await(let t of e)o.push(t)}else{let r=e({...t,baseUrl:v(),api:`anthropic-messages`},n,R(V({...a,apiKey:i},`streamAdobe[anthropic]`)));for await(let e of r)o.push(e)}o.end()}catch(e){console.error(`[adobe] Stream error:`,e instanceof Error?e.message:String(e)),o.push(U(t,e)),o.end()}})(),o},G=(e,r,a)=>{let o=i();return(async()=>{try{let i=await P();if(String(e.api).includes(`openai`)){let n=t({...e,baseUrl:`${v()}/v1`,api:`openai-completions`,compat:{...e.compat,supportsStore:!1,supportsDeveloperRole:!1}},r,R(V({...a,apiKey:i},`streamSimpleAdobe[openai]`)));for await(let e of n)o.push(e)}else{let t=n({...e,baseUrl:v(),api:`anthropic-messages`},r,R(V({...a,apiKey:i},`streamSimpleAdobe[anthropic]`)));for await(let e of t)o.push(e)}o.end()}catch(t){console.error(`[adobe] Stream error:`,t instanceof Error?t.message:String(t)),o.push(U(e,t)),o.end()}})(),o};async function K(){try{let e=await P(),t=v(),n=await fetch(`${t}/v1/models`,{headers:{Authorization:`Bearer ${e}`,[L]:`3.27.0`}});if(n.ok){let e=await n.json();if(e.data?.length){for(let t of e.data){let e={id:t.id,name:t.name};t.api!==void 0&&(e.api=t.api),t.context_window!==void 0&&(e.context_window=t.context_window),t.max_tokens!==void 0&&(e.max_tokens=t.max_tokens),t.reasoning!==void 0&&(e.reasoning=t.reasoning),t.input!==void 0&&(e.input=t.input),b.set(t.id,e)}let n=new Map;for(let e of l())try{for(let t of f(e))n.set(t.id,t)}catch{}return e.data.map(e=>{let r=n.get(e.id),i=`adobe-${e.api===`openai`?`openai`:`anthropic`}`;return r?{...r,provider:`adobe`,api:i}:{id:e.id,name:e.name??e.id,provider:`adobe`,api:i,baseUrl:t,contextWindow:2e5,maxTokens:16384,input:[`text`,`image`],cost:{input:0,output:0,cacheRead:0,cacheWrite:0},inputCost:0,outputCost:0,cacheReadCost:0,cacheWriteCost:0,reasoning:!0}})}}else console.warn(`[adobe] Proxy /v1/models returned ${n.status}, falling back to Anthropic models`)}catch(e){console.warn(`[adobe] Failed to fetch proxy models:`,e instanceof Error?e.message:String(e))}return f(`anthropic`).map(e=>({...e,provider:`adobe`,api:`adobe-anthropic`}))}var q=new Map;async function J(){let e=v(),t=q.get(e);if(t)return t;let n=await K();return q.set(e,n),n}function Y(){a({api:`adobe-anthropic`,stream:W,streamSimple:G}),a({api:`adobe-openai`,stream:W,streamSimple:G})}export{H as __resetAdobeSessionIdWarningCacheForTests,j as config,J as getAdobeModels,P as getValidAccessToken,F as isTokenExpired,Y as register};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{F as e}from"./main-B019n563.js";var t=e(`agent-bridge`),n=`__slicc_agent`,r=`agent-spawn-request`;function i(){let e={spawn(e){return new Promise((t,n)=>{let i=globalThis.chrome?.runtime;if(!i||typeof i.sendMessage!=`function`){n(Error(`agent: chrome.runtime.sendMessage not available`));return}let a=e=>{let r=i.lastError;if(r){n(Error(r.message??`chrome.runtime error`));return}if(e==null){n(Error(`agent: empty response from offscreen bridge`));return}let a=e;if(!a.ok){n(Error(a.error??`agent: offscreen bridge error`));return}if(!a.result){n(Error(`agent: offscreen bridge returned no result`));return}t(a.result)};try{i.sendMessage({source:`panel`,payload:{type:r,options:e}},a)}catch(e){n(e instanceof Error?e:Error(String(e)))}})}};return globalThis[n]=e,t.info(`agent bridge proxy published on globalThis.__slicc_agent`),e}export{i as publishAgentBridgeProxy};
|
package/dist/ui/assets/{agent-message-to-chat-DAB_RuwN.js → agent-message-to-chat-O6uJ723d.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{ut as e}from"./kernel-worker-
|
|
1
|
+
import{ut as e}from"./kernel-worker-BXAud9Z1.js";const t=new Set([`webhook`,`cron`,`sprinkle`,`fswatch`,`session-reload`,`navigate`,`upgrade`,`scoop-notify`,`scoop-idle`,`scoop-wait`]);function n(e){return e!=null&&t.has(e)}function r(t,n={}){let{source:r=`cone`,idSeed:c=d,hiddenToolNames:l=e}=n,f=[],h=null,g=new Set;for(let e of t){if(i(e)){let t=s(e.content);if(t.length===0)continue;let n=p(t);for(let t of n){if(t.body.length===0&&t.sender==null)continue;let n=t.sender?m(t.sender):null,r={id:c(),role:`user`,content:t.body,timestamp:e.timestamp};n&&(r.source=`lick`,r.channel=n),f.push(r)}h=null;continue}if(a(e)){let t=s(e.content),n=u(e),i=[];for(let e of n)l.has(e.name)?g.add(e.id):i.push(e);let a={id:c(),role:`assistant`,content:t,timestamp:e.timestamp,source:r};i.length>0&&(a.toolCalls=i),f.push(a),h=a;continue}if(o(e)){if(g.has(e.toolCallId))continue;let t=h?.toolCalls?.find(t=>t.id===e.toolCallId);if(!t)continue;t.result=s(e.content),t.isError=e.isError}}return f}function i(e){return e.role===`user`}function a(e){return e.role===`assistant`}function o(e){return e.role===`toolResult`}function s(e){if(typeof e==`string`)return e;if(!Array.isArray(e))return``;let t=[];for(let n of e)c(n)&&t.push(n.text);return t.join(``)}function c(e){return e.type===`text`}function l(e){return e.type===`toolCall`}function u(e){if(!Array.isArray(e.content))return[];let t=[];for(let n of e.content)l(n)&&t.push({id:n.id,name:n.name,input:n.arguments});return t}function d(){return Date.now().toString(36)+Math.random().toString(36).slice(2,8)}function f(e){if(!e.startsWith(`[`))return null;let n=e.indexOf(`] `);if(n<=0||e.lastIndexOf(`
|
|
2
2
|
`,n)!==-1)return null;let r=e.slice(n+2);if(r.startsWith(`User: `))return{sender:`User`,body:r.slice(6)};for(let e of t){let t=`${e}:`;if(!r.startsWith(t))continue;let n=r.indexOf(`
|
|
3
3
|
`),i=n===-1?r.length:n,a=r.slice(0,i),o=-1,s=a.indexOf(`[`,t.length);if(s>t.length&&(o=a.lastIndexOf(`: `,s)),o<t.length&&(o=r.indexOf(`: `,t.length)),!(o<0||o>=i))return{sender:r.slice(0,o),body:r.slice(o+2)}}let i=r.indexOf(`
|
|
4
4
|
`),a=i===-1?r.length:i,o=r.indexOf(`: `);if(o<=0||o>=a)return null;let s=r.slice(0,o);return s.includes(`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{A as e,G as t,M as n,O as r,Q as i,a,c as o,j as s,k as c,l,o as u,q as d,u as f}from"./kernel-worker-
|
|
1
|
+
import{A as e,G as t,M as n,O as r,Q as i,a,c as o,j as s,k as c,l,o as u,q as d,u as f}from"./kernel-worker-BXAud9Z1.js";function p(e,t,n,r,i){if(r===`m`)throw TypeError(`Private method is not writable`);if(r===`a`&&!i)throw TypeError(`Private accessor was defined without a setter`);if(typeof t==`function`?e!==t||!i:!t.has(e))throw TypeError(`Cannot write private member to an object whose class did not declare it`);return r===`a`?i.call(e,n):i?i.value=n:t.set(e,n),n}function m(e,t,n,r){if(n===`a`&&!r)throw TypeError(`Private accessor was defined without a getter`);if(typeof t==`function`?e!==t||!r:!t.has(e))throw TypeError(`Cannot read private member from an object whose class did not declare it`);return n===`m`?r:n===`a`?r.call(e):r?r.value:t.get(e)}let ee=function(){let{crypto:e}=globalThis;if(e?.randomUUID)return ee=e.randomUUID.bind(e),e.randomUUID();let t=new Uint8Array(1),n=e?()=>e.getRandomValues(t)[0]:()=>Math.random()*255&255;return`10000000-1000-4000-8000-100000000000`.replace(/[018]/g,e=>(e^n()&15>>e/4).toString(16))};function h(e){return typeof e==`object`&&!!e&&(`name`in e&&e.name===`AbortError`||`message`in e&&String(e.message).includes(`FetchRequestCanceledException`))}const g=e=>{if(e instanceof Error)return e;if(typeof e==`object`&&e){try{if(Object.prototype.toString.call(e)===`[object Error]`){let t=Error(e.message,e.cause?{cause:e.cause}:{});return e.stack&&(t.stack=e.stack),e.cause&&!t.cause&&(t.cause=e.cause),e.name&&(t.name=e.name),t}}catch{}try{return Error(JSON.stringify(e))}catch{}}return Error(e)};var _=class extends Error{},v=class e extends _{constructor(t,n,r,i,a){super(`${e.makeMessage(t,n,r)}`),this.status=t,this.headers=i,this.requestID=i?.get(`request-id`),this.error=n,this.type=a??null}static makeMessage(e,t,n){let r=t?.message?typeof t.message==`string`?t.message:JSON.stringify(t.message):t?JSON.stringify(t):n;return e&&r?`${e} ${r}`:e?`${e} status code (no body)`:r||`(no status code or body)`}static generate(t,n,r,i){if(!t||!i)return new te({message:r,cause:g(n)});let a=n,o=a?.error?.type;return t===400?new re(t,a,r,i,o):t===401?new ie(t,a,r,i,o):t===403?new ae(t,a,r,i,o):t===404?new oe(t,a,r,i,o):t===409?new se(t,a,r,i,o):t===422?new ce(t,a,r,i,o):t===429?new le(t,a,r,i,o):t>=500?new ue(t,a,r,i,o):new e(t,a,r,i,o)}},y=class extends v{constructor({message:e}={}){super(void 0,void 0,e||`Request was aborted.`,void 0)}},te=class extends v{constructor({message:e,cause:t}){super(void 0,void 0,e||`Connection error.`,void 0),t&&(this.cause=t)}},ne=class extends te{constructor({message:e}={}){super({message:e??`Request timed out.`})}},re=class extends v{},ie=class extends v{},ae=class extends v{},oe=class extends v{},se=class extends v{},ce=class extends v{},le=class extends v{},ue=class extends v{};const de=/^[a-z][a-z0-9+.-]*:/i,fe=e=>de.test(e);let pe=e=>(pe=Array.isArray,pe(e)),me=pe;function he(e){return typeof e==`object`?e??{}:{}}function ge(e){if(!e)return!0;for(let t in e)return!1;return!0}function _e(e,t){return Object.prototype.hasOwnProperty.call(e,t)}const ve=(e,t)=>{if(typeof t!=`number`||!Number.isInteger(t))throw new _(`${e} must be an integer`);if(t<0)throw new _(`${e} must be a positive integer`);return t},ye=e=>{try{return JSON.parse(e)}catch{return}},be=e=>new Promise(t=>setTimeout(t,e)),b=`0.91.1`,xe=()=>typeof window<`u`&&window.document!==void 0&&typeof navigator<`u`;function Se(){return typeof Deno<`u`&&Deno.build!=null?`deno`:typeof EdgeRuntime<`u`?`edge`:Object.prototype.toString.call(globalThis.process===void 0?0:globalThis.process)===`[object process]`?`node`:`unknown`}const Ce=()=>{let e=Se();if(e===`deno`)return{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":b,"X-Stainless-OS":Ee(Deno.build.os),"X-Stainless-Arch":Te(Deno.build.arch),"X-Stainless-Runtime":`deno`,"X-Stainless-Runtime-Version":typeof Deno.version==`string`?Deno.version:Deno.version?.deno??`unknown`};if(typeof EdgeRuntime<`u`)return{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":b,"X-Stainless-OS":`Unknown`,"X-Stainless-Arch":`other:${EdgeRuntime}`,"X-Stainless-Runtime":`edge`,"X-Stainless-Runtime-Version":globalThis.process.version};if(e===`node`)return{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":b,"X-Stainless-OS":Ee(globalThis.process.platform??`unknown`),"X-Stainless-Arch":Te(globalThis.process.arch??`unknown`),"X-Stainless-Runtime":`node`,"X-Stainless-Runtime-Version":globalThis.process.version??`unknown`};let t=we();return t?{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":b,"X-Stainless-OS":`Unknown`,"X-Stainless-Arch":`unknown`,"X-Stainless-Runtime":`browser:${t.browser}`,"X-Stainless-Runtime-Version":t.version}:{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":b,"X-Stainless-OS":`Unknown`,"X-Stainless-Arch":`unknown`,"X-Stainless-Runtime":`unknown`,"X-Stainless-Runtime-Version":`unknown`}};function we(){if(typeof navigator>`u`||!navigator)return null;for(let{key:e,pattern:t}of[{key:`edge`,pattern:/Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:`ie`,pattern:/MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:`ie`,pattern:/Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:`chrome`,pattern:/Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:`firefox`,pattern:/Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:`safari`,pattern:/(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/}]){let n=t.exec(navigator.userAgent);if(n)return{browser:e,version:`${n[1]||0}.${n[2]||0}.${n[3]||0}`}}return null}const Te=e=>e===`x32`?`x32`:e===`x86_64`||e===`x64`?`x64`:e===`arm`?`arm`:e===`aarch64`||e===`arm64`?`arm64`:e?`other:${e}`:`unknown`,Ee=e=>(e=e.toLowerCase(),e.includes(`ios`)?`iOS`:e===`android`?`Android`:e===`darwin`?`MacOS`:e===`win32`?`Windows`:e===`freebsd`?`FreeBSD`:e===`openbsd`?`OpenBSD`:e===`linux`?`Linux`:e?`Other:${e}`:`Unknown`);let De;const Oe=()=>De??=Ce();function ke(){if(typeof fetch<`u`)return fetch;throw Error("`fetch` is not defined as a global; Either pass `fetch` to the client, `new Anthropic({ fetch })` or polyfill the global, `globalThis.fetch = fetch`")}function Ae(...e){let t=globalThis.ReadableStream;if(t===void 0)throw Error("`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`");return new t(...e)}function je(e){let t=Symbol.asyncIterator in e?e[Symbol.asyncIterator]():e[Symbol.iterator]();return Ae({start(){},async pull(e){let{done:n,value:r}=await t.next();n?e.close():e.enqueue(r)},async cancel(){await t.return?.()}})}function Me(e){if(e[Symbol.asyncIterator])return e;let t=e.getReader();return{async next(){try{let e=await t.read();return e?.done&&t.releaseLock(),e}catch(e){throw t.releaseLock(),e}},async return(){let e=t.cancel();return t.releaseLock(),await e,{done:!0,value:void 0}},[Symbol.asyncIterator](){return this}}}async function Ne(e){if(typeof e!=`object`||!e)return;if(e[Symbol.asyncIterator]){await e[Symbol.asyncIterator]().return?.();return}let t=e.getReader(),n=t.cancel();t.releaseLock(),await n}const Pe=({headers:e,body:t})=>({bodyHeaders:{"content-type":`application/json`},body:JSON.stringify(t)});function Fe(e){return Object.entries(e).filter(([e,t])=>t!==void 0).map(([e,t])=>{if(typeof t==`string`||typeof t==`number`||typeof t==`boolean`)return`${encodeURIComponent(e)}=${encodeURIComponent(t)}`;if(t===null)return`${encodeURIComponent(e)}=`;throw new _(`Cannot stringify type ${typeof t}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`)}).join(`&`)}function Ie(e){let t=0;for(let n of e)t+=n.length;let n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n}let Le;function Re(e){let t;return(Le??=(t=new globalThis.TextEncoder,t.encode.bind(t)))(e)}let ze;function Be(e){let t;return(ze??=(t=new globalThis.TextDecoder,t.decode.bind(t)))(e)}var x,S,Ve=class{constructor(){x.set(this,void 0),S.set(this,void 0),p(this,x,new Uint8Array,`f`),p(this,S,null,`f`)}decode(e){if(e==null)return[];let t=e instanceof ArrayBuffer?new Uint8Array(e):typeof e==`string`?Re(e):e;p(this,x,Ie([m(this,x,`f`),t]),`f`);let n=[],r;for(;(r=He(m(this,x,`f`),m(this,S,`f`)))!=null;){if(r.carriage&&m(this,S,`f`)==null){p(this,S,r.index,`f`);continue}if(m(this,S,`f`)!=null&&(r.index!==m(this,S,`f`)+1||r.carriage)){n.push(Be(m(this,x,`f`).subarray(0,m(this,S,`f`)-1))),p(this,x,m(this,x,`f`).subarray(m(this,S,`f`)),`f`),p(this,S,null,`f`);continue}let e=m(this,S,`f`)===null?r.preceding:r.preceding-1,t=Be(m(this,x,`f`).subarray(0,e));n.push(t),p(this,x,m(this,x,`f`).subarray(r.index),`f`),p(this,S,null,`f`)}return n}flush(){return m(this,x,`f`).length?this.decode(`
|
|
2
2
|
`):[]}};x=new WeakMap,S=new WeakMap,Ve.NEWLINE_CHARS=new Set([`
|
|
3
3
|
`,`\r`]),Ve.NEWLINE_REGEXP=/\r\n|[\n\r]/g;function He(e,t){for(let n=t??0;n<e.length;n++){if(e[n]===10)return{preceding:n,index:n+1,carriage:!1};if(e[n]===13)return{preceding:n,index:n+1,carriage:!0}}return null}function Ue(e){for(let t=0;t<e.length-1;t++){if(e[t]===10&&e[t+1]===10||e[t]===13&&e[t+1]===13)return t+2;if(e[t]===13&&e[t+1]===10&&t+3<e.length&&e[t+2]===13&&e[t+3]===10)return t+4}return-1}const We={off:0,error:200,warn:300,info:400,debug:500},Ge=(e,t,n)=>{if(e){if(_e(We,e))return e;C(n).warn(`${t} was set to ${JSON.stringify(e)}, expected one of ${JSON.stringify(Object.keys(We))}`)}};function Ke(){}function qe(e,t,n){return!t||We[e]>We[n]?Ke:t[e].bind(t)}const Je={error:Ke,warn:Ke,info:Ke,debug:Ke};let Ye=new WeakMap;function C(e){let t=e.logger,n=e.logLevel??`off`;if(!t)return Je;let r=Ye.get(t);if(r&&r[0]===n)return r[1];let i={error:qe(`error`,t,n),warn:qe(`warn`,t,n),info:qe(`info`,t,n),debug:qe(`debug`,t,n)};return Ye.set(t,[n,i]),i}const w=e=>(e.options&&(e.options={...e.options},delete e.options.headers),e.headers&&=Object.fromEntries((e.headers instanceof Headers?[...e.headers]:Object.entries(e.headers)).map(([e,t])=>[e,e.toLowerCase()===`x-api-key`||e.toLowerCase()===`authorization`||e.toLowerCase()===`cookie`||e.toLowerCase()===`set-cookie`?`***`:t])),`retryOfRequestLogID`in e&&(e.retryOfRequestLogID&&(e.retryOf=e.retryOfRequestLogID),delete e.retryOfRequestLogID),e);var Xe,Ze=class e{constructor(e,t,n){this.iterator=e,Xe.set(this,void 0),this.controller=t,p(this,Xe,n,`f`)}static fromSSEResponse(t,n,r){let i=!1,a=r?C(r):console;async function*o(){if(i)throw new _("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");i=!0;let e=!1;try{for await(let e of Qe(t,n)){if(e.event===`completion`)try{yield JSON.parse(e.data)}catch(t){throw a.error(`Could not parse message into JSON:`,e.data),a.error(`From chunk:`,e.raw),t}if(e.event===`message_start`||e.event===`message_delta`||e.event===`message_stop`||e.event===`content_block_start`||e.event===`content_block_delta`||e.event===`content_block_stop`||e.event===`message`||e.event===`user.message`||e.event===`user.interrupt`||e.event===`user.tool_confirmation`||e.event===`user.custom_tool_result`||e.event===`agent.message`||e.event===`agent.thinking`||e.event===`agent.tool_use`||e.event===`agent.tool_result`||e.event===`agent.mcp_tool_use`||e.event===`agent.mcp_tool_result`||e.event===`agent.custom_tool_use`||e.event===`agent.thread_context_compacted`||e.event===`session.status_running`||e.event===`session.status_idle`||e.event===`session.status_rescheduled`||e.event===`session.status_terminated`||e.event===`session.error`||e.event===`session.deleted`||e.event===`span.model_request_start`||e.event===`span.model_request_end`)try{yield JSON.parse(e.data)}catch(t){throw a.error(`Could not parse message into JSON:`,e.data),a.error(`From chunk:`,e.raw),t}if(e.event!==`ping`&&e.event===`error`){let n=ye(e.data)??e.data,r=n?.error?.type;throw new v(void 0,n,void 0,t.headers,r)}}e=!0}catch(e){if(h(e))return;throw e}finally{e||n.abort()}}return new e(o,n,r)}static fromReadableStream(t,n,r){let i=!1;async function*a(){let e=new Ve,n=Me(t);for await(let t of n)for(let n of e.decode(t))yield n;for(let t of e.flush())yield t}async function*o(){if(i)throw new _("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");i=!0;let e=!1;try{for await(let t of a())e||t&&(yield JSON.parse(t));e=!0}catch(e){if(h(e))return;throw e}finally{e||n.abort()}}return new e(o,n,r)}[(Xe=new WeakMap,Symbol.asyncIterator)](){return this.iterator()}tee(){let t=[],n=[],r=this.iterator(),i=e=>({next:()=>{if(e.length===0){let e=r.next();t.push(e),n.push(e)}return e.shift()}});return[new e(()=>i(t),this.controller,m(this,Xe,`f`)),new e(()=>i(n),this.controller,m(this,Xe,`f`))]}toReadableStream(){let e=this,t;return Ae({async start(){t=e[Symbol.asyncIterator]()},async pull(e){try{let{value:n,done:r}=await t.next();if(r)return e.close();let i=Re(JSON.stringify(n)+`
|
|
4
4
|
`);e.enqueue(i)}catch(t){e.error(t)}},async cancel(){await t.return?.()}})}};async function*Qe(e,t){if(!e.body)throw t.abort(),globalThis.navigator!==void 0&&globalThis.navigator.product===`ReactNative`?new _(`The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api`):new _(`Attempted to iterate over a response with no body`);let n=new et,r=new Ve,i=Me(e.body);for await(let e of $e(i))for(let t of r.decode(e)){let e=n.decode(t);e&&(yield e)}for(let e of r.flush()){let t=n.decode(e);t&&(yield t)}}async function*$e(e){let t=new Uint8Array;for await(let n of e){if(n==null)continue;let e=n instanceof ArrayBuffer?new Uint8Array(n):typeof n==`string`?Re(n):n,r=new Uint8Array(t.length+e.length);r.set(t),r.set(e,t.length),t=r;let i;for(;(i=Ue(t))!==-1;)yield t.slice(0,i),t=t.slice(i)}t.length>0&&(yield t)}var et=class{constructor(){this.event=null,this.data=[],this.chunks=[]}decode(e){if(e.endsWith(`\r`)&&(e=e.substring(0,e.length-1)),!e){if(!this.event&&!this.data.length)return null;let e={event:this.event,data:this.data.join(`
|