@tangle-network/agent-app 0.63.28 → 0.63.30
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/{TimelineEditor-VB2UJ34D.js → TimelineEditor-MUY35ULL.js} +3 -3
- package/dist/app-auth/index.js +3 -3
- package/dist/assistant/index.js +9 -9
- package/dist/chat-react/index.js +3 -3
- package/dist/chat-routes/default-backend.d.ts +19 -2
- package/dist/chat-routes/hybrid-producer.d.ts +7 -2
- package/dist/chat-routes/index.js +4 -4
- package/dist/chat-routes/route-storage.d.ts +1 -1
- package/dist/chat-routes/router-producer.d.ts +2 -1
- package/dist/chat-routes/turn-route-contracts.d.ts +1 -1
- package/dist/chunk-53ZX7XZY.js +371 -0
- package/dist/chunk-53ZX7XZY.js.map +1 -0
- package/dist/{chunk-56JUV4DK.js → chunk-5AUZR655.js} +3335 -3020
- package/dist/chunk-5AUZR655.js.map +1 -0
- package/dist/{chunk-IVBREL7A.js → chunk-5HBIN366.js} +10 -10
- package/dist/{chunk-A7JD27SN.js → chunk-6UMIOEDR.js} +13 -13
- package/dist/{chunk-QUT3T2IN.js → chunk-L3QR274L.js} +11 -3
- package/dist/chunk-L3QR274L.js.map +1 -0
- package/dist/chunk-N425HGJW.js +261 -0
- package/dist/chunk-N425HGJW.js.map +1 -0
- package/dist/{chunk-DCJCZ7EP.js → chunk-QLZ6A73E.js} +37 -19
- package/dist/chunk-QLZ6A73E.js.map +1 -0
- package/dist/{chunk-ZZTPTCMY.js → chunk-XJXAULNI.js} +7 -7
- package/dist/conformance/cli.d.ts +2 -0
- package/dist/conformance/cli.js +67 -0
- package/dist/conformance/cli.js.map +1 -0
- package/dist/conformance/index.d.ts +3 -0
- package/dist/conformance/index.js +9 -0
- package/dist/conformance/index.js.map +1 -0
- package/dist/conformance/revision.d.ts +13 -0
- package/dist/conformance/run.d.ts +48 -0
- package/dist/conformance/session.d.ts +24 -0
- package/dist/conformance/turns.d.ts +37 -0
- package/dist/design-canvas/index.js +6 -6
- package/dist/design-canvas-react/index.js +4 -4
- package/dist/model-resolution/index.js +1 -1
- package/dist/operator/index.js +24 -252
- package/dist/operator/index.js.map +1 -1
- package/dist/platform/index.js +8 -8
- package/dist/public-consultation/index.d.ts +2 -2
- package/dist/public-consultation/index.js +4 -4
- package/dist/sandbox/computer-files.d.ts +67 -0
- package/dist/sandbox/computer-receipts.d.ts +46 -0
- package/dist/sandbox/computer-step.d.ts +78 -0
- package/dist/sandbox/index.d.ts +4 -0
- package/dist/sandbox/index.js +23 -1
- package/dist/sandbox/router-models.d.ts +26 -0
- package/dist/sandbox/sandbox-run-tool.d.ts +5 -4
- package/dist/sequences-react/index.js +3 -3
- package/dist/settings-react/index.js +1 -1
- package/dist/web-react/index.js +28 -28
- package/dist/workspace-react/index.js +5 -5
- package/package.json +8 -2
- package/dist/chunk-56JUV4DK.js.map +0 -1
- package/dist/chunk-DCJCZ7EP.js.map +0 -1
- package/dist/chunk-QUT3T2IN.js.map +0 -1
- /package/dist/{TimelineEditor-VB2UJ34D.js.map → TimelineEditor-MUY35ULL.js.map} +0 -0
- /package/dist/{chunk-IVBREL7A.js.map → chunk-5HBIN366.js.map} +0 -0
- /package/dist/{chunk-A7JD27SN.js.map → chunk-6UMIOEDR.js.map} +0 -0
- /package/dist/{chunk-ZZTPTCMY.js.map → chunk-XJXAULNI.js.map} +0 -0
|
@@ -2,13 +2,13 @@ import {
|
|
|
2
2
|
SEQUENCE_MEDIA_DRAG_TYPE,
|
|
3
3
|
TimelineEditor,
|
|
4
4
|
TimelineEditor_default
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-P4RRC4AO.js";
|
|
5
|
+
} from "./chunk-5HBIN366.js";
|
|
7
6
|
import "./chunk-SISVELAA.js";
|
|
7
|
+
import "./chunk-P4RRC4AO.js";
|
|
8
8
|
import "./chunk-7PULOECS.js";
|
|
9
9
|
export {
|
|
10
10
|
SEQUENCE_MEDIA_DRAG_TYPE,
|
|
11
11
|
TimelineEditor,
|
|
12
12
|
TimelineEditor_default as default
|
|
13
13
|
};
|
|
14
|
-
//# sourceMappingURL=TimelineEditor-
|
|
14
|
+
//# sourceMappingURL=TimelineEditor-MUY35ULL.js.map
|
package/dist/app-auth/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
noticeEmail
|
|
3
|
+
} from "../chunk-WOTWQ2ST.js";
|
|
1
4
|
import {
|
|
2
5
|
createAuthGuard,
|
|
3
6
|
createBetterAuthSessionCookieMinter,
|
|
4
7
|
createTangleSsoHandlers
|
|
5
8
|
} from "../chunk-JUQMVD4U.js";
|
|
6
|
-
import {
|
|
7
|
-
noticeEmail
|
|
8
|
-
} from "../chunk-WOTWQ2ST.js";
|
|
9
9
|
import "../chunk-DPTNKH22.js";
|
|
10
10
|
import "../chunk-RN4WPTBH.js";
|
|
11
11
|
import "../chunk-ALIWB2P3.js";
|
package/dist/assistant/index.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ReasoningRow,
|
|
3
3
|
chatToolCallPart
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-3HUFJ5LO.js";
|
|
4
|
+
} from "../chunk-6UMIOEDR.js";
|
|
6
5
|
import "../chunk-UHSUY6H6.js";
|
|
6
|
+
import "../chunk-3HUFJ5LO.js";
|
|
7
7
|
import "../chunk-7PULOECS.js";
|
|
8
8
|
import "../chunk-ZOS3D26Z.js";
|
|
9
|
+
import "../chunk-JNEWZCRF.js";
|
|
9
10
|
import "../chunk-Y6PRDUFJ.js";
|
|
11
|
+
import "../chunk-GEYACSFW.js";
|
|
10
12
|
import {
|
|
11
13
|
ChatComposer
|
|
12
|
-
} from "../chunk-
|
|
14
|
+
} from "../chunk-XJXAULNI.js";
|
|
13
15
|
import "../chunk-L7MB2LLM.js";
|
|
16
|
+
import "../chunk-KHJE7JAG.js";
|
|
14
17
|
import "../chunk-2VG6Q4TS.js";
|
|
15
18
|
import "../chunk-2HQP2CTA.js";
|
|
16
|
-
import "../chunk-E4AY62T2.js";
|
|
17
|
-
import "../chunk-SJWIZT7B.js";
|
|
18
|
-
import "../chunk-JNEWZCRF.js";
|
|
19
|
-
import "../chunk-KHJE7JAG.js";
|
|
20
19
|
import "../chunk-QAHBSKWG.js";
|
|
21
20
|
import {
|
|
22
21
|
ModelPicker
|
|
23
22
|
} from "../chunk-RO25WIVS.js";
|
|
24
23
|
import "../chunk-ZAMHLXNS.js";
|
|
25
|
-
import "../chunk-
|
|
24
|
+
import "../chunk-E4AY62T2.js";
|
|
25
|
+
import "../chunk-SJWIZT7B.js";
|
|
26
26
|
import "../chunk-TEZETVLE.js";
|
|
27
27
|
import "../chunk-ZA56ZOIT.js";
|
|
28
|
-
import "../chunk-RASGKEAL.js";
|
|
29
28
|
import {
|
|
30
29
|
AsyncView
|
|
31
30
|
} from "../chunk-AVP5SNIG.js";
|
|
31
|
+
import "../chunk-RASGKEAL.js";
|
|
32
32
|
import "../chunk-FQYAJYPW.js";
|
|
33
33
|
import "../chunk-P7UB7ZVP.js";
|
|
34
34
|
import "../chunk-B7CL7ENS.js";
|
package/dist/chat-react/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ComposerModeControls,
|
|
3
3
|
EntryComposer
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-XJXAULNI.js";
|
|
5
5
|
import "../chunk-L7MB2LLM.js";
|
|
6
|
-
import "../chunk-2HQP2CTA.js";
|
|
7
|
-
import "../chunk-SJWIZT7B.js";
|
|
8
6
|
import "../chunk-KHJE7JAG.js";
|
|
7
|
+
import "../chunk-2HQP2CTA.js";
|
|
9
8
|
import "../chunk-QAHBSKWG.js";
|
|
10
9
|
import "../chunk-RO25WIVS.js";
|
|
11
10
|
import "../chunk-ZAMHLXNS.js";
|
|
11
|
+
import "../chunk-SJWIZT7B.js";
|
|
12
12
|
import "../chunk-RASGKEAL.js";
|
|
13
13
|
import "../chunk-P7UB7ZVP.js";
|
|
14
14
|
import "../chunk-QGJOT6R6.js";
|
|
@@ -4,6 +4,11 @@ import { type StreamSandboxPromptOptions } from '../sandbox/prompt-options';
|
|
|
4
4
|
import type { ChatTurnStoreBindings } from './route-storage';
|
|
5
5
|
import { type ModelPolicy } from '../policy-filters/index';
|
|
6
6
|
import type { ChatTurnProduceArgs, ChatTurnHybridConfiguration } from './turn-route-contracts';
|
|
7
|
+
import type { RouterTurnTool } from '../runtime/router-turn';
|
|
8
|
+
import type { RouterTurnKey } from './router-producer';
|
|
9
|
+
import type { ComputerVault } from '../sandbox/computer-files';
|
|
10
|
+
import type { ComputerStepReceipts } from '../sandbox/computer-receipts';
|
|
11
|
+
import type { Outcome } from '../sandbox/outcome';
|
|
7
12
|
/** Worker bindings are explicit; no ambient deployment credentials replace product policy. */
|
|
8
13
|
export interface ChatTurnEnvironment {
|
|
9
14
|
DB?: ChatTurnStoreBindings['db'];
|
|
@@ -18,7 +23,7 @@ export interface ChatTurnEnvironment {
|
|
|
18
23
|
SANDBOX_GATEWAY_URL?: string;
|
|
19
24
|
}
|
|
20
25
|
/** Domain data for the default lane, instead of constructing producers or admission hooks. */
|
|
21
|
-
export interface ChatTurnDefaultBackend {
|
|
26
|
+
export interface ChatTurnDefaultBackend<TContext = unknown, TResource = unknown> {
|
|
22
27
|
model?: string;
|
|
23
28
|
systemPrompt?: string;
|
|
24
29
|
harness?: Harness;
|
|
@@ -28,9 +33,21 @@ export interface ChatTurnDefaultBackend {
|
|
|
28
33
|
shell?: SandboxRuntimeConfig;
|
|
29
34
|
/** Explicitly keep every turn on the sandbox lane. */
|
|
30
35
|
router?: false;
|
|
36
|
+
/** Who pays for the Router model call: the turn's key, or a per-turn lease (`createDelegatedTurnKeys`) the
|
|
37
|
+
* producer revokes when the turn settles. Default `TANGLE_API_KEY`. Started before the turn lock, like the call. */
|
|
38
|
+
funding?(args: ChatTurnProduceArgs<TContext, TResource>): RouterTurnKey | Promise<RouterTurnKey>;
|
|
39
|
+
/** The product's in-process tools for the Router model; `sandbox_run` is added after them. */
|
|
40
|
+
tools?(args: ChatTurnProduceArgs<TContext, TResource>): RouterTurnTool[] | Promise<RouterTurnTool[]>;
|
|
41
|
+
/** What the computer step does beyond running the task: copy its files into the product's Vault, keep durable
|
|
42
|
+
* receipts, and run a model the box key allows (`readSandboxRouterModels` with the payer's key). */
|
|
43
|
+
computer?: {
|
|
44
|
+
files?(args: ChatTurnProduceArgs<TContext, TResource>): ComputerVault | undefined;
|
|
45
|
+
receipts?: ComputerStepReceipts;
|
|
46
|
+
allowedModels?(args: ChatTurnProduceArgs<TContext, TResource>, signal: AbortSignal): Promise<Outcome<readonly string[] | null>>;
|
|
47
|
+
};
|
|
31
48
|
}
|
|
32
49
|
export declare function defaultChatShell(projectId: string, env: ChatTurnEnvironment, config: ChatTurnDefaultBackend): SandboxRuntimeConfig;
|
|
33
|
-
export declare function createDefaultChatBackend<TContext, TResource>(projectId: string, env: ChatTurnEnvironment, config: ChatTurnDefaultBackend, bindings?: ChatTurnStoreBindings, modelPolicy?: ModelPolicy): {
|
|
50
|
+
export declare function createDefaultChatBackend<TContext, TResource>(projectId: string, env: ChatTurnEnvironment, config: ChatTurnDefaultBackend<TContext, TResource>, bindings?: ChatTurnStoreBindings, modelPolicy?: ModelPolicy): {
|
|
34
51
|
when: (args: ChatTurnProduceArgs<TContext, TResource>) => boolean;
|
|
35
52
|
router(args: ChatTurnProduceArgs<TContext, TResource>): Promise<ChatTurnHybridConfiguration>;
|
|
36
53
|
sandbox: (args: ChatTurnProduceArgs<TContext, TResource>) => Promise<{
|
|
@@ -39,6 +39,7 @@ import type { SandboxInstance } from '@tangle-network/sandbox';
|
|
|
39
39
|
import type { RouterTurnTool } from '../runtime/router-turn';
|
|
40
40
|
import { type EscalationHint, type EscalationInput } from '../sandbox/escalation-speculator';
|
|
41
41
|
import { type SandboxRunToolOptions } from '../sandbox/sandbox-run-tool';
|
|
42
|
+
import { type ComputerStepOptions } from '../sandbox/computer-step';
|
|
42
43
|
import type { PersistedChatMessageForTurn } from '../stream/index';
|
|
43
44
|
import { type RouterTurnProducerOptions } from './router-producer';
|
|
44
45
|
import type { ChatTurnRouteProducer } from './turn-routes';
|
|
@@ -51,8 +52,12 @@ export interface HybridTurnBox {
|
|
|
51
52
|
acquire(signal: AbortSignal): Promise<SandboxInstance>;
|
|
52
53
|
/** A start admission already began ({@link startHybridBox}); the producer takes it as the turn's start. */
|
|
53
54
|
started?: Promise<SandboxInstance>;
|
|
54
|
-
/** Runs the task on the box and returns its answer
|
|
55
|
-
runTask
|
|
55
|
+
/** Runs the task on the box and returns its answer. Omit it and pass `computer` for agent-app's computer step. */
|
|
56
|
+
runTask?: SandboxRunToolOptions['runTask'];
|
|
57
|
+
/** agent-app's computer step ({@link createComputerStep}): the first of the turn's models the box key allows, one
|
|
58
|
+
* session value, stable step ids, durable receipts and the copy of the step's files into the product's Vault.
|
|
59
|
+
* `parentExecutionId` defaults to the turn's execution id on the chat route, else the trace id. */
|
|
60
|
+
computer?: ComputerStepOptions;
|
|
56
61
|
/** Wall-clock cap for one `sandbox_run` call, box start included. Default 4 minutes. */
|
|
57
62
|
timeoutMs?: number;
|
|
58
63
|
warm?: SandboxRunToolOptions['warm'];
|
|
@@ -79,15 +79,15 @@ import {
|
|
|
79
79
|
turnCarriesFiles,
|
|
80
80
|
turnPromptText,
|
|
81
81
|
withProducerStream
|
|
82
|
-
} from "../chunk-
|
|
82
|
+
} from "../chunk-QLZ6A73E.js";
|
|
83
83
|
import "../chunk-CWO2LHXH.js";
|
|
84
84
|
import {
|
|
85
85
|
sniffMimeFromName
|
|
86
86
|
} from "../chunk-DPTNKH22.js";
|
|
87
|
-
import "../chunk-RN4WPTBH.js";
|
|
88
87
|
import "../chunk-4DBHC63F.js";
|
|
88
|
+
import "../chunk-RN4WPTBH.js";
|
|
89
89
|
import "../chunk-MM6RLOXF.js";
|
|
90
|
-
import "../chunk-
|
|
90
|
+
import "../chunk-5AUZR655.js";
|
|
91
91
|
import "../chunk-F4TUZYMX.js";
|
|
92
92
|
import {
|
|
93
93
|
redactErrorMessage
|
|
@@ -156,7 +156,7 @@ import {
|
|
|
156
156
|
turnResponseEventFor,
|
|
157
157
|
validateSandboxMentionPath
|
|
158
158
|
} from "../chunk-QGJOT6R6.js";
|
|
159
|
-
import "../chunk-
|
|
159
|
+
import "../chunk-L3QR274L.js";
|
|
160
160
|
import "../chunk-XELWWXJJ.js";
|
|
161
161
|
import "../chunk-DSMGS4IV.js";
|
|
162
162
|
import "../chunk-ACB7KOQ6.js";
|
|
@@ -24,7 +24,7 @@ export declare function createDefaultTurnLock<TContext>(store: Pick<ChatTurnStor
|
|
|
24
24
|
export type ResolvedChatTurnRoutesOptions<TContext, TResource = unknown> = Omit<CreateChatTurnRoutesOptions<TContext, TResource>, 'turnStore' | 'turnLock' | 'produce'> & {
|
|
25
25
|
turnStore: TurnEventStore;
|
|
26
26
|
turnLock?: Exclude<CreateChatTurnRoutesOptions<TContext, TResource>['turnLock'], false>;
|
|
27
|
-
produce: Exclude<CreateChatTurnRoutesOptions<TContext, TResource>['produce'], undefined | import('./default-backend').ChatTurnDefaultBackend
|
|
27
|
+
produce: Exclude<CreateChatTurnRoutesOptions<TContext, TResource>['produce'], undefined | import('./default-backend').ChatTurnDefaultBackend<TContext, TResource>>;
|
|
28
28
|
};
|
|
29
29
|
export declare function turnStorageBindings(options: {
|
|
30
30
|
turnStore: TurnEventStore | ChatTurnStoreBindings;
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
import { composeRouterTurnPromptSections, type RouterTurnEvent, type RouterTurnFailure, type RouterTurnOptions, type RouterTurnOutcome, type RouterTurnPromptOptions } from '../runtime/router-turn';
|
|
12
12
|
import type { ChatTurnRouteProducer } from './turn-routes';
|
|
13
13
|
import type { ProducerWireEvent } from './wire';
|
|
14
|
-
|
|
14
|
+
/** The turn's model key: a plain key, or a per-turn lease whose fetch and revocation belong to the producer. */
|
|
15
|
+
export type RouterTurnKey = string | {
|
|
15
16
|
key: string;
|
|
16
17
|
fetchImpl?: typeof fetch;
|
|
17
18
|
revoke(): Promise<void>;
|
|
@@ -604,7 +604,7 @@ export interface CreateChatTurnRoutesOptions<TContext = void, TResource = unknow
|
|
|
604
604
|
* when selects the Router backend (default true); false selects sandbox,
|
|
605
605
|
* which always starts after admission. A function also starts after admission.
|
|
606
606
|
* Reused user rows always finish admission before either backend starts. */
|
|
607
|
-
produce?: import('./default-backend').ChatTurnDefaultBackend | ((args: ChatTurnProduceArgs<TContext, TResource>) => ChatTurnRouteProducer | Promise<ChatTurnRouteProducer>) | {
|
|
607
|
+
produce?: import('./default-backend').ChatTurnDefaultBackend<TContext, TResource> | ((args: ChatTurnProduceArgs<TContext, TResource>) => ChatTurnRouteProducer | Promise<ChatTurnRouteProducer>) | {
|
|
608
608
|
router(args: ChatTurnProduceArgs<TContext, TResource>): ChatTurnRouterBackend | Promise<ChatTurnRouterBackend>;
|
|
609
609
|
when?(args: ChatTurnProduceArgs<TContext, TResource>): boolean;
|
|
610
610
|
sandbox?(args: ChatTurnProduceArgs<TContext, TResource>): ChatTurnSandboxBackend | Promise<ChatTurnSandboxBackend>;
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createOperatorClient
|
|
3
|
+
} from "./chunk-N425HGJW.js";
|
|
4
|
+
|
|
5
|
+
// src/conformance/session.ts
|
|
6
|
+
var Failure = class extends Error {
|
|
7
|
+
};
|
|
8
|
+
var REQUEST_MS = 3e4;
|
|
9
|
+
var Jar = class {
|
|
10
|
+
byOrigin = /* @__PURE__ */ new Map();
|
|
11
|
+
header(url) {
|
|
12
|
+
return [...this.byOrigin.get(new URL(url).origin) ?? []].map(([name, value]) => `${name}=${value}`).join("; ");
|
|
13
|
+
}
|
|
14
|
+
async send(url, init = {}) {
|
|
15
|
+
const headers = new Headers(init.headers);
|
|
16
|
+
const cookie = this.header(url);
|
|
17
|
+
if (cookie) headers.set("cookie", cookie);
|
|
18
|
+
const response = await fetch(url, { ...init, headers, redirect: "manual", signal: init.signal ?? AbortSignal.timeout(REQUEST_MS) });
|
|
19
|
+
this.absorb(url, response);
|
|
20
|
+
return response;
|
|
21
|
+
}
|
|
22
|
+
absorb(url, response) {
|
|
23
|
+
const origin = new URL(url).origin;
|
|
24
|
+
const jar = this.byOrigin.get(origin) ?? /* @__PURE__ */ new Map();
|
|
25
|
+
for (const line of response.headers.getSetCookie()) {
|
|
26
|
+
const [pair = "", ...attributes] = line.split(";");
|
|
27
|
+
const eq = pair.indexOf("=");
|
|
28
|
+
if (eq < 1) continue;
|
|
29
|
+
const name = pair.slice(0, eq).trim();
|
|
30
|
+
const value = pair.slice(eq + 1).trim();
|
|
31
|
+
const attribute = (key) => attributes.map((item) => item.trim()).find((item) => item.toLowerCase().startsWith(`${key}=`))?.slice(key.length + 1);
|
|
32
|
+
const maxAge = attribute("max-age");
|
|
33
|
+
const expires = attribute("expires");
|
|
34
|
+
const gone = !value || maxAge !== void 0 && Number(maxAge) <= 0 || maxAge === void 0 && expires !== void 0 && Date.parse(expires) <= Date.now();
|
|
35
|
+
if (gone) jar.delete(name);
|
|
36
|
+
else jar.set(name, value);
|
|
37
|
+
}
|
|
38
|
+
this.byOrigin.set(origin, jar);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var snippet = async (response) => (await response.text().catch(() => "")).replace(/\s+/g, " ").slice(0, 160);
|
|
42
|
+
async function postSignIn(jar, origin, email, password) {
|
|
43
|
+
for (let attempt = 0; ; attempt += 1) {
|
|
44
|
+
const response = await jar.send(`${origin}/api/auth/sign-in/email`, {
|
|
45
|
+
method: "POST",
|
|
46
|
+
headers: { "content-type": "application/json", origin },
|
|
47
|
+
body: JSON.stringify({ email, password })
|
|
48
|
+
});
|
|
49
|
+
if (response.status !== 429 || attempt === 2) return response;
|
|
50
|
+
const wait = Number(response.headers.get("retry-after"));
|
|
51
|
+
await response.body?.cancel().catch(() => {
|
|
52
|
+
});
|
|
53
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(20, Number.isFinite(wait) && wait > 0 ? wait : 5) * 1e3));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async function passwordSignIn(jar, origin, email, password) {
|
|
57
|
+
const response = await postSignIn(jar, origin, email, password);
|
|
58
|
+
if (response.status !== 200) throw new Failure(`password sign-in answered ${response.status}: ${await snippet(response)}`);
|
|
59
|
+
}
|
|
60
|
+
var TANGLE_AUTH_PATH = /(^|\/)auth\/tangle\//;
|
|
61
|
+
async function ssoSignIn(jar, origin, email, password) {
|
|
62
|
+
const answers = [];
|
|
63
|
+
let location = null;
|
|
64
|
+
for (const path of ["/auth/tangle/start", "/api/auth/tangle/start"]) {
|
|
65
|
+
const start = await jar.send(`${origin}${path}`);
|
|
66
|
+
location = start.headers.get("location");
|
|
67
|
+
if (location) break;
|
|
68
|
+
answers.push(`${path} answered ${start.status}`);
|
|
69
|
+
}
|
|
70
|
+
if (!location) throw new Failure(`SSO start sent the member nowhere (${answers.join("; ")})`);
|
|
71
|
+
const authorize = new URL(location, origin);
|
|
72
|
+
const platform = authorize.origin;
|
|
73
|
+
const member = await postSignIn(jar, platform, email, password);
|
|
74
|
+
if (member.status !== 200) throw new Failure(`Platform sign-in answered ${member.status}: ${await snippet(member)}`);
|
|
75
|
+
let next = authorize.href;
|
|
76
|
+
for (let hop = 0; hop < 8; hop += 1) {
|
|
77
|
+
const response = await jar.send(next);
|
|
78
|
+
const redirect = response.headers.get("location");
|
|
79
|
+
if (!redirect) throw new Failure(`SSO stopped at ${new URL(next).pathname} with ${response.status}`);
|
|
80
|
+
const url = new URL(redirect, next);
|
|
81
|
+
if (url.origin === origin && !TANGLE_AUTH_PATH.test(url.pathname)) {
|
|
82
|
+
if (url.pathname.startsWith("/login") || url.searchParams.has("error") || url.searchParams.get("connection") === "failed") {
|
|
83
|
+
throw new Failure(`the app's SSO callback sent the member to ${url.pathname}${url.search.slice(0, 80)}`);
|
|
84
|
+
}
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
next = url.href;
|
|
88
|
+
}
|
|
89
|
+
throw new Failure("SSO did not return to the app within 8 redirects");
|
|
90
|
+
}
|
|
91
|
+
async function sessionAccepted(session) {
|
|
92
|
+
const who = await session.fetch("/api/auth/get-session");
|
|
93
|
+
if (who.status === 200) {
|
|
94
|
+
const body = await who.json().catch(() => null);
|
|
95
|
+
if (typeof body?.user?.id === "string" && body.user.id) return "GET /api/auth/get-session returned the user";
|
|
96
|
+
}
|
|
97
|
+
const workspaces = await session.fetch("/api/workspaces");
|
|
98
|
+
if (workspaces.status === 200) return "GET /api/workspaces answered 200 as the member";
|
|
99
|
+
throw new Failure(`signed in, but the app does not accept the session: GET /api/auth/get-session answered ${who.status}, GET /api/workspaces ${workspaces.status}`);
|
|
100
|
+
}
|
|
101
|
+
async function signIn(input) {
|
|
102
|
+
const jar = new Jar();
|
|
103
|
+
if (input.mode === "password") await passwordSignIn(jar, input.origin, input.email, input.password);
|
|
104
|
+
else await ssoSignIn(jar, input.origin, input.email, input.password);
|
|
105
|
+
const session = {
|
|
106
|
+
origin: input.origin,
|
|
107
|
+
fetch: (path, init = {}) => {
|
|
108
|
+
const headers = new Headers(init.headers);
|
|
109
|
+
if (!headers.has("origin")) headers.set("origin", input.origin);
|
|
110
|
+
return jar.send(`${input.origin}${path}`, { ...init, headers });
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
return { session, detail: `${input.mode}: ${await sessionAccepted(session)}` };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/conformance/revision.ts
|
|
117
|
+
var REVISION_HEADER = /^x-[a-z0-9-]+-(revision|version)$/i;
|
|
118
|
+
var REQUEST_MS2 = 2e4;
|
|
119
|
+
var text = (value) => typeof value === "string" && value.trim() ? value.trim() : null;
|
|
120
|
+
function fromHealth(body) {
|
|
121
|
+
if (!body || typeof body !== "object") return null;
|
|
122
|
+
const record = body;
|
|
123
|
+
const release = record.release && typeof record.release === "object" ? record.release : {};
|
|
124
|
+
return text(record.revision) ?? text(release.revision) ?? text(release.sha) ?? text(release.tag);
|
|
125
|
+
}
|
|
126
|
+
function fromHeaders(response) {
|
|
127
|
+
for (const [name, value] of response.headers) if (REVISION_HEADER.test(name) && value.trim()) return { name, value: value.trim() };
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
async function readRevision(origin, expect) {
|
|
131
|
+
const looked = [];
|
|
132
|
+
const found = await (async () => {
|
|
133
|
+
for (const path of ["/api/health", "/"]) {
|
|
134
|
+
let response;
|
|
135
|
+
try {
|
|
136
|
+
response = await fetch(`${origin}${path}`, { headers: { accept: "application/json" }, redirect: "manual", signal: AbortSignal.timeout(REQUEST_MS2) });
|
|
137
|
+
} catch (error) {
|
|
138
|
+
looked.push(`GET ${path} failed (${error instanceof Error ? error.name : "error"})`);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const header = fromHeaders(response);
|
|
142
|
+
if (path === "/api/health" && response.ok) {
|
|
143
|
+
const revision = fromHealth(await response.json().catch(() => null));
|
|
144
|
+
if (revision) return { revision, source: "GET /api/health" };
|
|
145
|
+
}
|
|
146
|
+
if (header) return { revision: header.value, source: `GET ${path} ${header.name}` };
|
|
147
|
+
await response.body?.cancel().catch(() => {
|
|
148
|
+
});
|
|
149
|
+
looked.push(`GET ${path} answered ${response.status} without a revision`);
|
|
150
|
+
}
|
|
151
|
+
return null;
|
|
152
|
+
})();
|
|
153
|
+
if (!found) throw new Failure(`the app serves no readable revision (${looked.join("; ")})`);
|
|
154
|
+
if (expect) {
|
|
155
|
+
const [a, b] = [found.revision.toLowerCase(), expect.trim().toLowerCase()];
|
|
156
|
+
if (b.length < 7 || !(a.startsWith(b) || b.startsWith(a))) {
|
|
157
|
+
throw new Failure(`the app serves revision ${found.revision} (${found.source}), not the expected ${expect}`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return found;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// src/conformance/turns.ts
|
|
164
|
+
import { createHash, randomBytes, randomUUID } from "crypto";
|
|
165
|
+
var REQUEST_MS3 = 3e4;
|
|
166
|
+
var KEY_LIFETIME_MS = 60 * 6e4;
|
|
167
|
+
async function mintKey(session) {
|
|
168
|
+
const response = await session.fetch("/api/keys", {
|
|
169
|
+
method: "POST",
|
|
170
|
+
headers: { "content-type": "application/json" },
|
|
171
|
+
signal: AbortSignal.timeout(REQUEST_MS3),
|
|
172
|
+
body: JSON.stringify({
|
|
173
|
+
name: `conformance ${(/* @__PURE__ */ new Date()).toISOString()}`,
|
|
174
|
+
scopes: ["operator:read", "operator:run"],
|
|
175
|
+
expiresAt: new Date(Date.now() + KEY_LIFETIME_MS).toISOString(),
|
|
176
|
+
workspaceIds: []
|
|
177
|
+
})
|
|
178
|
+
});
|
|
179
|
+
if (response.status === 404) {
|
|
180
|
+
throw new Failure("the app has no key route (POST /api/keys answered 404), so a conformance turn has no credential; give it an operator key");
|
|
181
|
+
}
|
|
182
|
+
const body = await response.json().catch(() => null);
|
|
183
|
+
if (!response.ok || typeof body?.id !== "string" || typeof body.key !== "string") {
|
|
184
|
+
throw new Failure(`POST /api/keys answered ${response.status}: ${typeof body?.error === "string" ? body.error.slice(0, 160) : "no key in the response"}`);
|
|
185
|
+
}
|
|
186
|
+
return { id: body.id, key: body.key };
|
|
187
|
+
}
|
|
188
|
+
async function revokeKey(session, id) {
|
|
189
|
+
const byPath = await session.fetch(`/api/keys/${encodeURIComponent(id)}`, { method: "DELETE", signal: AbortSignal.timeout(REQUEST_MS3) });
|
|
190
|
+
if (byPath.ok) return;
|
|
191
|
+
const byBody = await session.fetch("/api/keys", {
|
|
192
|
+
method: "DELETE",
|
|
193
|
+
headers: { "content-type": "application/json" },
|
|
194
|
+
body: JSON.stringify({ id }),
|
|
195
|
+
signal: AbortSignal.timeout(REQUEST_MS3)
|
|
196
|
+
});
|
|
197
|
+
if (byBody.ok) return;
|
|
198
|
+
throw new Failure(`the minted key ${id} was not revoked: DELETE /api/keys/:id answered ${byPath.status}, DELETE /api/keys ${byBody.status} (it expires within the hour)`);
|
|
199
|
+
}
|
|
200
|
+
async function openOperatorAccess({ origin, key, workspace, requestMs }) {
|
|
201
|
+
const client = createOperatorClient({
|
|
202
|
+
origin,
|
|
203
|
+
getApiKey: () => key,
|
|
204
|
+
fetchImpl: (url, init) => fetch(url, { ...init, signal: init?.signal ? AbortSignal.any([init.signal, AbortSignal.timeout(requestMs)]) : AbortSignal.timeout(requestMs) })
|
|
205
|
+
});
|
|
206
|
+
const described = await client.describe();
|
|
207
|
+
if (!described.succeeded) throw new Failure(`GET /api/operator/v1 answered ${described.status} ${described.code}: ${described.error.slice(0, 160)}`);
|
|
208
|
+
const scopes = described.value.principal.scopes;
|
|
209
|
+
const missing = ["operator:read", "operator:run"].filter((scope) => !scopes.includes(scope) && !scopes.includes("*"));
|
|
210
|
+
if (missing.length) throw new Failure(`the operator key lacks ${missing.join(" and ")}`);
|
|
211
|
+
const listed = await client.listWorkspaces();
|
|
212
|
+
if (!listed.succeeded) throw new Failure(`GET /api/operator/v1/workspaces answered ${listed.status} ${listed.code}: ${listed.error.slice(0, 160)}`);
|
|
213
|
+
const chosen = workspace ? listed.value.filter((candidate) => candidate.id === workspace || candidate.name === workspace) : listed.value.length === 1 ? listed.value : [];
|
|
214
|
+
if (chosen.length !== 1) {
|
|
215
|
+
const names = listed.value.slice(0, 12).map((candidate) => `${candidate.name} (${candidate.id.slice(0, 8)})`).join(", ");
|
|
216
|
+
throw new Failure(workspace ? `${chosen.length} of the key's ${listed.value.length} workspaces match "${workspace}": ${names}` : `the key reaches ${listed.value.length} workspaces; name the canary workspace: ${names}`);
|
|
217
|
+
}
|
|
218
|
+
return { client, workspace: chosen[0], scopes };
|
|
219
|
+
}
|
|
220
|
+
var reply = (turn) => (turn.reply?.content ?? "").trim();
|
|
221
|
+
async function runTurn(access, title, content, turnMs) {
|
|
222
|
+
const turnId = randomUUID();
|
|
223
|
+
const started = await access.client.startTurn(access.workspace.id, { turnId, content, title });
|
|
224
|
+
if (!started.succeeded) throw new Failure(`the turn was refused: ${started.status} ${started.code}: ${started.error.slice(0, 200)}`);
|
|
225
|
+
const where = `thread ${started.value.threadId}`;
|
|
226
|
+
const settled = await access.client.waitForTurn(access.workspace.id, started.value.threadId, started.value.turnId, { timeoutMs: turnMs });
|
|
227
|
+
if (!settled.succeeded) throw new Failure(`reading the turn answered ${settled.status} ${settled.code}: ${settled.error.slice(0, 160)} (${where})`);
|
|
228
|
+
const turn = settled.value;
|
|
229
|
+
if (turn.state === "failed") throw new Failure(`the turn failed${turn.failure?.code ? ` (${turn.failure.code})` : ""}: ${(turn.failure?.message ?? "no message").slice(0, 300)} (${where})`);
|
|
230
|
+
if (turn.state === "input-required" || turn.approvals.length > 0) throw new Failure(`the turn is waiting on a decision, which no one can answer in a conformance run (${where})`);
|
|
231
|
+
if (turn.state !== "succeeded") throw new Failure(`the turn had not settled after ${Math.round(turnMs / 1e3)} s (state ${turn.state}; ${where})`);
|
|
232
|
+
return { turn, where };
|
|
233
|
+
}
|
|
234
|
+
async function plainTurn(access, turnMs) {
|
|
235
|
+
const { turn, where } = await runTurn(
|
|
236
|
+
access,
|
|
237
|
+
"Conformance: plain turn",
|
|
238
|
+
"Conformance check: reply with one short sentence confirming you can answer.",
|
|
239
|
+
turnMs
|
|
240
|
+
);
|
|
241
|
+
if (!reply(turn)) throw new Failure(`the turn succeeded with an empty reply (${where})`);
|
|
242
|
+
return `${reply(turn).length} characters (${where})`;
|
|
243
|
+
}
|
|
244
|
+
async function computerTurn(access, turnMs, proof, fileDir) {
|
|
245
|
+
const nonce = `conformance-${randomBytes(12).toString("hex")}`;
|
|
246
|
+
if (proof === "digest") {
|
|
247
|
+
const digest = createHash("sha256").update(nonce).digest("hex");
|
|
248
|
+
const { turn, where: where2 } = await runTurn(
|
|
249
|
+
access,
|
|
250
|
+
"Conformance: computer turn",
|
|
251
|
+
`Conformance check: run this exact shell command on the workspace computer (sandbox_run when you have it), then reply with only the 64-character hex digest it prints:
|
|
252
|
+
printf %s '${nonce}' | sha256sum`,
|
|
253
|
+
turnMs
|
|
254
|
+
);
|
|
255
|
+
if (!reply(turn).includes(digest)) {
|
|
256
|
+
throw new Failure(`the reply does not hold the digest of the fresh nonce, so the computer did not run the command: "${reply(turn).slice(0, 160)}" (${where2})`);
|
|
257
|
+
}
|
|
258
|
+
return `the reply carries the digest ${digest.slice(0, 12)}\u2026 (${where2})`;
|
|
259
|
+
}
|
|
260
|
+
const path = `${fileDir.replace(/\/+$/, "")}/${nonce}.md`;
|
|
261
|
+
const { where } = await runTurn(
|
|
262
|
+
access,
|
|
263
|
+
"Conformance: computer turn",
|
|
264
|
+
`Conformance check: use the workspace computer to save a file at ${path} whose whole content is this one line, then reply with the word saved:
|
|
265
|
+
${nonce}`,
|
|
266
|
+
turnMs
|
|
267
|
+
);
|
|
268
|
+
const read = await access.client.readFile(access.workspace.id, path);
|
|
269
|
+
if (!read.succeeded) throw new Failure(`the turn succeeded, but the app does not serve ${path}: ${read.status} ${read.code} (${where})`);
|
|
270
|
+
if (read.value.content.trim() !== nonce) {
|
|
271
|
+
throw new Failure(`${path} holds ${JSON.stringify(read.value.content.slice(0, 80))}, not the nonce (${where})`);
|
|
272
|
+
}
|
|
273
|
+
return `the app serves ${path} with the nonce (${where})`;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// src/conformance/run.ts
|
|
277
|
+
var DEFAULT_TURN_MS = 3e5;
|
|
278
|
+
function describe(error) {
|
|
279
|
+
if (error instanceof Failure) return error.message;
|
|
280
|
+
if (error instanceof Error) {
|
|
281
|
+
const cause = error.cause;
|
|
282
|
+
return `${error.name}: ${error.message}${typeof cause?.code === "string" ? ` (${cause.code})` : ""}`;
|
|
283
|
+
}
|
|
284
|
+
return String(error);
|
|
285
|
+
}
|
|
286
|
+
async function checkDeployedApp(options) {
|
|
287
|
+
const origin = options.origin.replace(/\/+$/, "");
|
|
288
|
+
const turnMs = options.turnMs ?? DEFAULT_TURN_MS;
|
|
289
|
+
const secrets = [options.member?.password, options.operatorKey].filter((value) => Boolean(value && value.length >= 6));
|
|
290
|
+
const redact = (text2) => secrets.reduce((out, secret) => out.split(secret).join("[redacted]"), text2);
|
|
291
|
+
const results = [];
|
|
292
|
+
const record = (result) => {
|
|
293
|
+
const clean = { ...result, ...result.cause ? { cause: redact(result.cause) } : {}, ...result.detail ? { detail: redact(result.detail) } : {} };
|
|
294
|
+
results.push(clean);
|
|
295
|
+
options.onResult?.(clean);
|
|
296
|
+
};
|
|
297
|
+
async function check(name, body) {
|
|
298
|
+
const at = (/* @__PURE__ */ new Date()).toISOString();
|
|
299
|
+
const started = Date.now();
|
|
300
|
+
const base = { at, app: options.app, url: origin, check: name };
|
|
301
|
+
try {
|
|
302
|
+
const { value, detail } = await body();
|
|
303
|
+
record({ ...base, status: "pass", ms: Date.now() - started, ...detail ? { detail } : {} });
|
|
304
|
+
return value;
|
|
305
|
+
} catch (error) {
|
|
306
|
+
record({ ...base, status: "fail", ms: Date.now() - started, cause: describe(error) });
|
|
307
|
+
return void 0;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
const blocked = (name, because) => record({ at: (/* @__PURE__ */ new Date()).toISOString(), app: options.app, url: origin, check: name, status: "blocked", ms: 0, cause: because });
|
|
311
|
+
let session;
|
|
312
|
+
if (!options.member) {
|
|
313
|
+
const at = (/* @__PURE__ */ new Date()).toISOString();
|
|
314
|
+
record({ at, app: options.app, url: origin, check: "sign-in", status: "fail", ms: 0, cause: "no member is configured: give the canary member email and password" });
|
|
315
|
+
} else {
|
|
316
|
+
const member = options.member;
|
|
317
|
+
session = await check("sign-in", async () => {
|
|
318
|
+
const signedIn = await signIn({ origin, ...member });
|
|
319
|
+
return { value: signedIn.session, detail: signedIn.detail };
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
await check("revision", async () => {
|
|
323
|
+
const served = await readRevision(origin, options.expectRevision);
|
|
324
|
+
return { value: served, detail: `${served.revision} (${served.source})` };
|
|
325
|
+
});
|
|
326
|
+
let minted = null;
|
|
327
|
+
let access;
|
|
328
|
+
if (!options.operatorKey && !session) {
|
|
329
|
+
blocked("operator-access", "blocked by sign-in: no operator key is configured, and the member did not sign in to mint one");
|
|
330
|
+
} else {
|
|
331
|
+
access = await check("operator-access", async () => {
|
|
332
|
+
let secret = options.operatorKey;
|
|
333
|
+
if (!secret) {
|
|
334
|
+
const created = await mintKey(session);
|
|
335
|
+
secrets.push(created.key);
|
|
336
|
+
secret = created.key;
|
|
337
|
+
minted = { id: created.id };
|
|
338
|
+
}
|
|
339
|
+
const opened = await openOperatorAccess({ origin, key: secret, workspace: options.workspace, requestMs: turnMs + 6e4 });
|
|
340
|
+
return {
|
|
341
|
+
value: opened,
|
|
342
|
+
detail: `${minted ? "a minted one-hour key" : "the configured operator key"} reaches "${opened.workspace.name}" with ${opened.scopes.join(", ")}`
|
|
343
|
+
};
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
if (access) {
|
|
347
|
+
const open = access;
|
|
348
|
+
await check("plain-turn", async () => ({ value: true, detail: await plainTurn(open, turnMs) }));
|
|
349
|
+
await check("computer-turn", async () => ({
|
|
350
|
+
value: true,
|
|
351
|
+
detail: await computerTurn(open, turnMs, options.computer ?? "digest", options.fileDir ?? "proof")
|
|
352
|
+
}));
|
|
353
|
+
} else {
|
|
354
|
+
blocked("plain-turn", "blocked by operator-access");
|
|
355
|
+
blocked("computer-turn", "blocked by operator-access");
|
|
356
|
+
}
|
|
357
|
+
const mintedKey = minted;
|
|
358
|
+
if (mintedKey && session) {
|
|
359
|
+
const member = session;
|
|
360
|
+
await check("key-revoke", async () => {
|
|
361
|
+
await revokeKey(member, mintedKey.id);
|
|
362
|
+
return { value: true, detail: "the minted key was revoked" };
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
return results;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export {
|
|
369
|
+
checkDeployedApp
|
|
370
|
+
};
|
|
371
|
+
//# sourceMappingURL=chunk-53ZX7XZY.js.map
|