@tangle-network/agent-app 0.60.246 → 0.60.248
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/agent-profiles/d1.js +3 -3
- package/dist/agent-profiles/index.js +3 -3
- package/dist/assistant/index.js +5 -5
- package/dist/billing/index.js +1 -1
- package/dist/chat-react/index.js +3 -3
- package/dist/chat-routes/index.js +23 -16
- package/dist/chat-routes/index.js.map +1 -1
- package/dist/chat-routes/wire.d.ts +2 -0
- package/dist/chat-store/index.js +2 -2
- package/dist/{chunk-PYG2N2JX.js → chunk-23JUSUUB.js} +2 -2
- package/dist/{chunk-QHRMM2WA.js → chunk-5BJHKQ33.js} +4 -4
- package/dist/{chunk-YHRWZZJN.js → chunk-5TSRFF5W.js} +1 -1
- package/dist/chunk-5TSRFF5W.js.map +1 -0
- package/dist/{chunk-VRV75STU.js → chunk-7TZA2TAM.js} +2 -2
- package/dist/{chunk-LSXJJL4I.js → chunk-BDCC6UVW.js} +4 -4
- package/dist/{chunk-2UIRJPC6.js → chunk-BYP54FMI.js} +3 -3
- package/dist/{chunk-PALGMOU3.js → chunk-CFGBGIRK.js} +2 -2
- package/dist/{chunk-YJHE73TF.js → chunk-LLV5VVYJ.js} +4 -1
- package/dist/chunk-LLV5VVYJ.js.map +1 -0
- package/dist/{chunk-2ZRXJ3NO.js → chunk-NHVSO47Q.js} +2 -2
- package/dist/{chunk-EJ4VTQNA.js → chunk-OJ6NYR3I.js} +3 -3
- package/dist/{chunk-DUGIVKNA.js → chunk-ORQD4AUO.js} +30 -4
- package/dist/chunk-ORQD4AUO.js.map +1 -0
- package/dist/{chunk-GMC5DO2O.js → chunk-QTWTZYXC.js} +41 -18
- package/dist/chunk-QTWTZYXC.js.map +1 -0
- package/dist/{chunk-F5FFOIS5.js → chunk-UFQM46NV.js} +2 -2
- package/dist/{chunk-HJ63OGYD.js → chunk-WCXHXCER.js} +2 -2
- package/dist/{chunk-UHSICXRD.js → chunk-WSQFNMIA.js} +5 -5
- package/dist/{chunk-UHSICXRD.js.map → chunk-WSQFNMIA.js.map} +1 -1
- package/dist/{chunk-QFNBFNM7.js → chunk-XEAZWJ3W.js} +2 -2
- package/dist/{chunk-BBYUWYEL.js → chunk-ZLUQYQ4P.js} +2 -2
- package/dist/operator/index.js +2 -2
- package/dist/preset-cloudflare/index.js +3 -3
- package/dist/public-consultation/index.js +4 -4
- package/dist/runtime/index.js +6 -4
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/loop.d.ts +1 -0
- package/dist/runtime/openai-stream.d.ts +4 -0
- package/dist/runtime/router-turn.d.ts +44 -13
- package/dist/runtime/router-turn.js +5 -3
- package/dist/sandbox/index.js +7 -7
- package/dist/tools/index.js +4 -4
- package/dist/turn-trace/index.js +2 -2
- package/dist/turn-trace/recorder.d.ts +7 -0
- package/dist/web-react/index.js +5 -5
- package/dist/work-product/index.js +2 -2
- package/package.json +2 -2
- package/dist/chunk-DUGIVKNA.js.map +0 -1
- package/dist/chunk-GMC5DO2O.js.map +0 -1
- package/dist/chunk-YHRWZZJN.js.map +0 -1
- package/dist/chunk-YJHE73TF.js.map +0 -1
- /package/dist/{chunk-PYG2N2JX.js.map → chunk-23JUSUUB.js.map} +0 -0
- /package/dist/{chunk-QHRMM2WA.js.map → chunk-5BJHKQ33.js.map} +0 -0
- /package/dist/{chunk-VRV75STU.js.map → chunk-7TZA2TAM.js.map} +0 -0
- /package/dist/{chunk-LSXJJL4I.js.map → chunk-BDCC6UVW.js.map} +0 -0
- /package/dist/{chunk-2UIRJPC6.js.map → chunk-BYP54FMI.js.map} +0 -0
- /package/dist/{chunk-PALGMOU3.js.map → chunk-CFGBGIRK.js.map} +0 -0
- /package/dist/{chunk-2ZRXJ3NO.js.map → chunk-NHVSO47Q.js.map} +0 -0
- /package/dist/{chunk-EJ4VTQNA.js.map → chunk-OJ6NYR3I.js.map} +0 -0
- /package/dist/{chunk-F5FFOIS5.js.map → chunk-UFQM46NV.js.map} +0 -0
- /package/dist/{chunk-HJ63OGYD.js.map → chunk-WCXHXCER.js.map} +0 -0
- /package/dist/{chunk-QFNBFNM7.js.map → chunk-XEAZWJ3W.js.map} +0 -0
- /package/dist/{chunk-BBYUWYEL.js.map → chunk-ZLUQYQ4P.js.map} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ToolInputError,
|
|
3
3
|
validateOpenUIJsonNode
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-WSQFNMIA.js";
|
|
5
5
|
|
|
6
6
|
// src/tools/render-ui-schema.ts
|
|
7
7
|
function parseRenderUiSchema(value) {
|
|
@@ -25,4 +25,4 @@ function parseRenderUiSchema(value) {
|
|
|
25
25
|
export {
|
|
26
26
|
parseRenderUiSchema
|
|
27
27
|
};
|
|
28
|
-
//# sourceMappingURL=chunk-
|
|
28
|
+
//# sourceMappingURL=chunk-XEAZWJ3W.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
runRouterTurn
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-QTWTZYXC.js";
|
|
4
4
|
|
|
5
5
|
// src/runtime/protected-model.ts
|
|
6
6
|
import {
|
|
@@ -219,4 +219,4 @@ export {
|
|
|
219
219
|
createRouterProtectedModelPort,
|
|
220
220
|
runProtectedRouterTurn
|
|
221
221
|
};
|
|
222
|
-
//# sourceMappingURL=chunk-
|
|
222
|
+
//# sourceMappingURL=chunk-ZLUQYQ4P.js.map
|
package/dist/operator/index.js
CHANGED
|
@@ -5,14 +5,14 @@ import {
|
|
|
5
5
|
} from "../chunk-XB4KZVUV.js";
|
|
6
6
|
import {
|
|
7
7
|
parseChatAttachmentInputs
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-NHVSO47Q.js";
|
|
9
9
|
import {
|
|
10
10
|
createApiKeyFetch
|
|
11
11
|
} from "../chunk-RN4WPTBH.js";
|
|
12
12
|
import {
|
|
13
13
|
messageHasTurnId
|
|
14
14
|
} from "../chunk-YG66IHDU.js";
|
|
15
|
-
import "../chunk-
|
|
15
|
+
import "../chunk-5TSRFF5W.js";
|
|
16
16
|
import "../chunk-TXD5HXLE.js";
|
|
17
17
|
|
|
18
18
|
// src/operator/contract.ts
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "../chunk-7KKOFMLD.js";
|
|
4
4
|
import {
|
|
5
5
|
createWorkspaceKeyManager
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-LLV5VVYJ.js";
|
|
7
7
|
import {
|
|
8
8
|
SANDBOX_TRANSIENT_DEADLINE_MS,
|
|
9
9
|
SandboxTransientDeadlineError,
|
|
@@ -12,8 +12,8 @@ import {
|
|
|
12
12
|
} from "../chunk-4LBCTFBP.js";
|
|
13
13
|
import {
|
|
14
14
|
parseRenderUiSchema
|
|
15
|
-
} from "../chunk-
|
|
16
|
-
import "../chunk-
|
|
15
|
+
} from "../chunk-XEAZWJ3W.js";
|
|
16
|
+
import "../chunk-WSQFNMIA.js";
|
|
17
17
|
|
|
18
18
|
// src/preset-cloudflare/workflow-instance.ts
|
|
19
19
|
async function ensureCloudflareWorkflowInstance(binding, input) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createChatTurnRoutes,
|
|
3
3
|
streamChatRouteAsSandboxEvents
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-BDCC6UVW.js";
|
|
5
5
|
import "../chunk-TCGZFSN5.js";
|
|
6
6
|
import "../chunk-FENBDSIW.js";
|
|
7
7
|
import "../chunk-RN4WPTBH.js";
|
|
@@ -10,15 +10,15 @@ import "../chunk-Z4RD5UF7.js";
|
|
|
10
10
|
import "../chunk-YG66IHDU.js";
|
|
11
11
|
import "../chunk-ISP6ZH3G.js";
|
|
12
12
|
import "../chunk-MM6RLOXF.js";
|
|
13
|
-
import "../chunk-
|
|
13
|
+
import "../chunk-23JUSUUB.js";
|
|
14
14
|
import "../chunk-ZVEEWGDK.js";
|
|
15
|
-
import "../chunk-
|
|
15
|
+
import "../chunk-5TSRFF5W.js";
|
|
16
16
|
import "../chunk-TXD5HXLE.js";
|
|
17
17
|
import "../chunk-ZGUXI5SI.js";
|
|
18
18
|
import "../chunk-6VQCFJWP.js";
|
|
19
19
|
import "../chunk-LQYIBL3G.js";
|
|
20
20
|
import "../chunk-XELWWXJJ.js";
|
|
21
|
-
import "../chunk-
|
|
21
|
+
import "../chunk-ORQD4AUO.js";
|
|
22
22
|
|
|
23
23
|
// src/public-consultation/index.ts
|
|
24
24
|
import { searchKnowledge } from "@tangle-network/agent-knowledge";
|
package/dist/runtime/index.js
CHANGED
|
@@ -2,12 +2,13 @@ import {
|
|
|
2
2
|
ProtectedModelSettlementError,
|
|
3
3
|
createRouterProtectedModelPort,
|
|
4
4
|
runProtectedRouterTurn
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-ZLUQYQ4P.js";
|
|
6
6
|
import {
|
|
7
7
|
DURABLE_HOP_BUDGET_MS,
|
|
8
8
|
asksForLanguage,
|
|
9
9
|
budgetTurnKnowledge,
|
|
10
10
|
composeRouterTurnPrompt,
|
|
11
|
+
composeRouterTurnPromptSections,
|
|
11
12
|
createOpenAICompatCompletionTurn,
|
|
12
13
|
createOpenAICompatStreamTurn,
|
|
13
14
|
createOpenAIResponsesTurn,
|
|
@@ -24,8 +25,8 @@ import {
|
|
|
24
25
|
turnKnowledgeInstructions,
|
|
25
26
|
workspaceKnowledgeForTurn,
|
|
26
27
|
workspaceTurnCheckpoints
|
|
27
|
-
} from "../chunk-
|
|
28
|
-
import "../chunk-
|
|
28
|
+
} from "../chunk-QTWTZYXC.js";
|
|
29
|
+
import "../chunk-UFQM46NV.js";
|
|
29
30
|
import {
|
|
30
31
|
DEFAULT_TANGLE_BILLING_ENFORCEMENT_ENV_VAR,
|
|
31
32
|
DEFAULT_TANGLE_ROUTER_BASE_URL,
|
|
@@ -52,7 +53,7 @@ import {
|
|
|
52
53
|
resolveCatalogModelId,
|
|
53
54
|
sortModelsByFreshness
|
|
54
55
|
} from "../chunk-AMUXRAUO.js";
|
|
55
|
-
import "../chunk-
|
|
56
|
+
import "../chunk-ORQD4AUO.js";
|
|
56
57
|
|
|
57
58
|
// src/runtime/certified-delivery.ts
|
|
58
59
|
import {
|
|
@@ -175,6 +176,7 @@ export {
|
|
|
175
176
|
buildCatalog,
|
|
176
177
|
catalogModelForId,
|
|
177
178
|
composeRouterTurnPrompt,
|
|
179
|
+
composeRouterTurnPromptSections,
|
|
178
180
|
createCertifiedDelivery,
|
|
179
181
|
createOpenAICompatCompletionTurn,
|
|
180
182
|
createOpenAICompatStreamTurn,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/runtime/certified-delivery.ts","../../src/runtime/surface-profile.ts"],"sourcesContent":["/**\n * Application profile composition using Runtime's certified-guidance source.\n *\n * The shell adapts the prompt source to the application's resolved profile;\n * Runtime owns pulling, cache lifetime, concurrent refresh and retained guidance.\n * Only prompt-compatible guidance is folded here. Tool definitions, execution\n * permissions, MCP servers and files are not installed from certified material.\n * The complete profile remains available through `current()` for inspection and\n * the product's separately authorized materialization path.\n */\nimport {\n createCertifiedPromptSource,\n type CertifiedProfile,\n type CertifiedPromptSourceOptions,\n} from '@tangle-network/agent-runtime/intelligence'\nimport type { ResolvedAgentProfile } from './agent'\n\n/** Pull coordinates, refresh cadence and timeout owned by the shared source. */\nexport type CertifiedDeliveryConfig = CertifiedPromptSourceOptions\n\n/** Adapt certified prompt guidance without granting execution authority. */\nexport interface CertifiedDelivery {\n /** Refresh on the source's cadence and compose the current prompt guidance.\n * Other resolved profile fields pass through unchanged. */\n composeProfile(base: ResolvedAgentProfile): Promise<ResolvedAgentProfile>\n /** Force a pull now, coalescing with an in-flight pull. Best-effort; not a\n * post-activation revision barrier or a permission-revocation protocol. */\n refresh(): Promise<void>\n /** Last successfully pulled profile, or null before a successful pull. */\n current(): CertifiedProfile | null\n}\n\nexport function createCertifiedDelivery(config: CertifiedDeliveryConfig): CertifiedDelivery {\n const source = createCertifiedPromptSource(config)\n return {\n async composeProfile(base) {\n return { ...base, systemPrompt: await source.compose(base.systemPrompt) }\n },\n refresh: () => source.refresh({ force: true }),\n current: source.current,\n }\n}\n","/**\n * Surface-scoped profile overlay — the seam letting any product page (a\n * sequence editor, a brief composer, a dataset view) add MCP servers, a prompt\n * addendum, and permission tightening to the workspace agent profile for turns\n * initiated FROM that surface, without the chat orchestrator knowing any\n * surface's specifics. The orchestrator resolves `(kind, ctx)` through a\n * registry the REQUEST HANDLER constructs per request (construction is a Map\n * build — cheap) and merges the result into the base profile it was about to\n * send to the sandbox. Per-request construction is the trust mechanism, not an\n * optimization target: each `build()` closes over server-trusted request state\n * (env bindings, secrets, the AUTHENTICATED user/workspace), which on Workers\n * exists only per request — a startup-built registry would force identity\n * through the untrusted client `ctx`.\n *\n * SECURITY INVARIANT: the surface `kind` and the ids inside `ctx` arrive on\n * the client request and are pure ROUTING data — never trusted content, never\n * identity. Identity comes from the closure (see above). The registered\n * `build()` runs server-side only: it validates the routing ids against the\n * product's access control, then mints its own URLs from server configuration\n * (`buildHttpMcpServer` in ../tools). A client can therefore never inject an\n * arbitrary MCP url, header, or credential into the agent profile: the\n * overlay's `mcp` values are typed as {@link SurfaceMcpServer} (= the\n * server-built `AppToolMcpServer` entry shape), and only build() constructs\n * them.\n *\n * The credential itself never appears in the overlay. Since the tagged-config\n * contract (`agent-interface` 0.38.0) the `Authorization` header is a\n * `secret-ref` naming a box-environment variable, which the sandbox resolves\n * privately; `build()` supplies that key NAME from server configuration and the\n * product writes the value through `SandboxRuntimeConfig.env` at creation or\n * refreshes it through `SandboxRuntimeConfig.runtimeEnv` before retained-box\n * bootstrap. The value remains workspace-scoped because every member and turn\n * shares the box; runtime renewal does not create a per-user secret channel.\n */\n\nimport type { AppToolMcpServer } from '../tools/mcp'\n\n/** Sandbox permission posture values, ranked deny > ask > allow for merging. */\nexport type SurfacePermissionValue = 'allow' | 'ask' | 'deny'\n\n/** The only MCP entry shape an overlay may carry: the server-built bridge\n * entry from ../tools/mcp (transport, url, headers, and capability token all\n * assembled server-side). The alias exists so overlay authors reach for the\n * builders in ../tools rather than hand-rolling `{ url: ctx.url }` shapes\n * that would let request data become a dialable endpoint. */\nexport type SurfaceMcpServer = AppToolMcpServer\n\n/** What one surface contributes to the agent profile for a single turn. */\nexport interface SurfaceOverlay {\n /** MCP servers to mount for this turn, keyed by tool-routing name. Names\n * must not collide with the base profile's — see {@link mergeSurfaceOverlay}. */\n mcp?: Record<string, SurfaceMcpServer>\n /** Appended to the base system-prompt addendum with a blank-line separator. */\n promptAddendum?: string\n /** Per-key posture the surface wants for its turns. Merging is monotone\n * fail-closed: the stricter of base/overlay wins, so a surface can tighten\n * the workspace posture but never relax it. */\n permissions?: Record<string, SurfacePermissionValue>\n}\n\n/**\n * One registered surface kind. `TCtx` is the shape build() expects — a CLAIM\n * about the client payload, not a guarantee: the registry hands build() the\n * request's `ctx` unvalidated, so build() must treat every field as an\n * untrusted id (resolve it through access control that throws on a bad or\n * foreign id) before minting anything from it.\n */\nexport interface SurfaceKindDefinition<TCtx> {\n kind: string\n build: (ctx: TCtx) => SurfaceOverlay | Promise<SurfaceOverlay>\n}\n\n/** The variance-erased form a registry accepts (`build` is contravariant in\n * `TCtx`, so every concrete definition is assignable to this). */\nexport type AnySurfaceKind = SurfaceKindDefinition<never>\n\n/**\n * Declare one surface kind. The `kind` string is the client-visible routing\n * key (e.g. `'sequences'`); `build` is the server-side factory that turns a\n * validated ctx into the overlay for one turn.\n */\nexport function defineSurfaceKind<TCtx>(opts: {\n kind: string\n build: (ctx: TCtx) => SurfaceOverlay | Promise<SurfaceOverlay>\n}): SurfaceKindDefinition<TCtx> {\n if (typeof opts.kind !== 'string' || opts.kind.length === 0 || /\\s/.test(opts.kind)) {\n throw new Error(`surface kind must be a non-empty string without whitespace (got ${JSON.stringify(opts.kind)})`)\n }\n if (typeof opts.build !== 'function') {\n throw new Error(`surface kind '${opts.kind}' requires a build function`)\n }\n return { kind: opts.kind, build: opts.build }\n}\n\n/** Resolve and build the overlay for a given surface kind within a turn context */\nexport interface SurfaceRegistry {\n /** Build the overlay for one turn. Throws on an unknown kind — an unknown\n * surface is a routing bug (client and server registries drifted), and\n * silently returning an empty overlay would strip the surface's tools from\n * the turn with no signal anywhere. Build errors propagate unwrapped. */\n resolve(kind: string, ctx: unknown): Promise<SurfaceOverlay>\n}\n\n/**\n * Assemble the product's surface registry from its registered kinds. Duplicate\n * kinds throw at construction: two builders behind one routing key would make\n * the mounted toolset depend on registration order.\n */\nexport function createSurfaceRegistry(kinds: readonly AnySurfaceKind[]): SurfaceRegistry {\n const byKind = new Map<string, AnySurfaceKind>()\n for (const definition of kinds) {\n if (byKind.has(definition.kind)) {\n throw new Error(`duplicate surface kind '${definition.kind}' — each kind must be registered exactly once`)\n }\n byKind.set(definition.kind, definition)\n }\n\n return {\n async resolve(kind, ctx) {\n const definition = byKind.get(kind)\n if (!definition) {\n const known = [...byKind.keys()].join(', ') || '(none)'\n throw new Error(\n `unknown surface kind '${kind}' — registered kinds: ${known}. ` +\n 'An unknown surface is a routing bug: register the kind via defineSurfaceKind before clients can reference it.',\n )\n }\n // The trust boundary where static ctx typing ends: the request payload is\n // handed to build() as-is, and build() validates it (see SurfaceKindDefinition).\n const overlay = await definition.build(ctx as never)\n assertSurfaceOverlay(overlay, `surface kind '${kind}'`)\n return overlay\n },\n }\n}\n\n/** Base-profile slice the merge reads/writes. Real callers pass their full\n * profile object; every field outside this slice passes through untouched. */\nexport interface SurfaceMergeBase {\n mcp?: Record<string, unknown>\n systemPromptAddendum?: string\n permissions?: Record<string, SurfacePermissionValue>\n}\n\nconst PERMISSION_SEVERITY: Record<SurfacePermissionValue, number> = { allow: 0, ask: 1, deny: 2 }\n\n/**\n * Merge one surface overlay into a base profile, returning a new object\n * (the base is never mutated; untouched nested records are shared by\n * reference).\n *\n * - `mcp`: overlay servers are added under their own names. A name already\n * present on the base THROWS — a collision is two servers claiming one\n * routing name, and renaming either silently would corrupt tool routing for\n * whichever caller expected the original binding.\n * - `systemPromptAddendum`: the overlay's `promptAddendum` appends after a\n * blank-line separator (no separator when the base has no addendum).\n * - `permissions`: per key the STRICTER value wins (deny > ask > allow). A\n * surface can tighten the base posture for its turns; a base 'deny' survives\n * any overlay.\n */\nexport function mergeSurfaceOverlay<TBase extends SurfaceMergeBase>(\n base: TBase,\n overlay: SurfaceOverlay,\n): TBase & SurfaceMergeBase {\n assertSurfaceOverlay(overlay, 'surface overlay')\n const merged: SurfaceMergeBase = { ...base }\n\n if (overlay.mcp && Object.keys(overlay.mcp).length > 0) {\n const baseMcp = base.mcp ?? {}\n const collisions = Object.keys(overlay.mcp).filter((name) => name in baseMcp)\n if (collisions.length > 0) {\n throw new Error(\n `surface overlay MCP name collision: ${collisions.map((n) => `'${n}'`).join(', ')} already exist on the base profile. ` +\n 'Two servers cannot claim one name — give the surface server a distinct name.',\n )\n }\n merged.mcp = { ...baseMcp, ...overlay.mcp }\n }\n\n if (overlay.promptAddendum !== undefined) {\n merged.systemPromptAddendum = base.systemPromptAddendum\n ? `${base.systemPromptAddendum}\\n\\n${overlay.promptAddendum}`\n : overlay.promptAddendum\n }\n\n if (overlay.permissions && Object.keys(overlay.permissions).length > 0) {\n const permissions: Record<string, SurfacePermissionValue> = { ...(base.permissions ?? {}) }\n for (const [key, value] of Object.entries(overlay.permissions)) {\n const existing = permissions[key]\n permissions[key] =\n existing === undefined || PERMISSION_SEVERITY[value] > PERMISSION_SEVERITY[existing] ? value : existing\n }\n merged.permissions = permissions\n }\n\n // merged began as a shallow copy of base; only the three slice fields were\n // replaced, so the intersection type is the true shape.\n return merged as TBase & SurfaceMergeBase\n}\n\n/** Reject overlays a build() (or hand-rolled caller) malformed, with the exact\n * field named: a relative MCP url, a blank addendum, or an off-vocabulary\n * permission would otherwise surface only as an opaque sandbox failure. */\nfunction assertSurfaceOverlay(overlay: SurfaceOverlay, label: string): void {\n if (overlay.promptAddendum !== undefined) {\n if (typeof overlay.promptAddendum !== 'string' || overlay.promptAddendum.trim().length === 0) {\n throw new Error(`${label}: promptAddendum must be a non-blank string when provided`)\n }\n }\n if (overlay.mcp !== undefined) {\n for (const [name, server] of Object.entries(overlay.mcp)) {\n if (name.trim().length === 0) throw new Error(`${label}: MCP server names must be non-empty`)\n if (server.transport !== 'http') {\n throw new Error(`${label}: MCP server '${name}' must use transport 'http' (got ${JSON.stringify((server as { transport?: unknown }).transport)})`)\n }\n let parsed: URL\n try {\n parsed = new URL(server.url)\n } catch {\n throw new Error(`${label}: MCP server '${name}' url must be an absolute URL (got ${JSON.stringify(server.url)})`)\n }\n if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {\n throw new Error(`${label}: MCP server '${name}' url must be http(s) (got ${JSON.stringify(server.url)})`)\n }\n }\n }\n if (overlay.permissions !== undefined) {\n for (const [key, value] of Object.entries(overlay.permissions)) {\n if (!(value in PERMISSION_SEVERITY)) {\n throw new Error(`${label}: permission '${key}' must be 'allow' | 'ask' | 'deny' (got ${JSON.stringify(value)})`)\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA;AAAA,EACE;AAAA,OAGK;AAkBA,SAAS,wBAAwB,QAAoD;AAC1F,QAAM,SAAS,4BAA4B,MAAM;AACjD,SAAO;AAAA,IACL,MAAM,eAAe,MAAM;AACzB,aAAO,EAAE,GAAG,MAAM,cAAc,MAAM,OAAO,QAAQ,KAAK,YAAY,EAAE;AAAA,IAC1E;AAAA,IACA,SAAS,MAAM,OAAO,QAAQ,EAAE,OAAO,KAAK,CAAC;AAAA,IAC7C,SAAS,OAAO;AAAA,EAClB;AACF;;;ACwCO,SAAS,kBAAwB,MAGR;AAC9B,MAAI,OAAO,KAAK,SAAS,YAAY,KAAK,KAAK,WAAW,KAAK,KAAK,KAAK,KAAK,IAAI,GAAG;AACn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,SAAS,CAAC,GAAG;AAAA,MACnJ;AACA,UAAI;AACJ,UAAI;AACF,iBAAS,IAAI,IAAI,OAAO,GAAG;AAAA,MAC7B,QAAQ;AACN,cAAM,IAAI,MAAM,GAAG,KAAK,iBAAiB,IAAI,sCAAsC,KAAK,UAAU,OAAO,GAAG,CAAC,GAAG;AAAA,MAClH;AACA,UAAI,OAAO,aAAa,WAAW,OAAO,aAAa,UAAU;AAC/D,cAAM,IAAI,MAAM,GAAG,KAAK,iBAAiB,IAAI,8BAA8B,KAAK,UAAU,OAAO,GAAG,CAAC,GAAG;AAAA,MAC1G;AAAA,IACF;AAAA,EACF;AACA,MAAI,QAAQ,gBAAgB,QAAW;AACrC,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,QAAQ,WAAW,GAAG;AAC9D,UAAI,EAAE,SAAS,sBAAsB;AACnC,cAAM,IAAI,MAAM,GAAG,KAAK,iBAAiB,GAAG,2CAA2C,KAAK,UAAU,KAAK,CAAC,GAAG;AAAA,MACjH;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/certified-delivery.ts","../../src/runtime/surface-profile.ts"],"sourcesContent":["/**\n * Application profile composition using Runtime's certified-guidance source.\n *\n * The shell adapts the prompt source to the application's resolved profile;\n * Runtime owns pulling, cache lifetime, concurrent refresh and retained guidance.\n * Only prompt-compatible guidance is folded here. Tool definitions, execution\n * permissions, MCP servers and files are not installed from certified material.\n * The complete profile remains available through `current()` for inspection and\n * the product's separately authorized materialization path.\n */\nimport {\n createCertifiedPromptSource,\n type CertifiedProfile,\n type CertifiedPromptSourceOptions,\n} from '@tangle-network/agent-runtime/intelligence'\nimport type { ResolvedAgentProfile } from './agent'\n\n/** Pull coordinates, refresh cadence and timeout owned by the shared source. */\nexport type CertifiedDeliveryConfig = CertifiedPromptSourceOptions\n\n/** Adapt certified prompt guidance without granting execution authority. */\nexport interface CertifiedDelivery {\n /** Refresh on the source's cadence and compose the current prompt guidance.\n * Other resolved profile fields pass through unchanged. */\n composeProfile(base: ResolvedAgentProfile): Promise<ResolvedAgentProfile>\n /** Force a pull now, coalescing with an in-flight pull. Best-effort; not a\n * post-activation revision barrier or a permission-revocation protocol. */\n refresh(): Promise<void>\n /** Last successfully pulled profile, or null before a successful pull. */\n current(): CertifiedProfile | null\n}\n\nexport function createCertifiedDelivery(config: CertifiedDeliveryConfig): CertifiedDelivery {\n const source = createCertifiedPromptSource(config)\n return {\n async composeProfile(base) {\n return { ...base, systemPrompt: await source.compose(base.systemPrompt) }\n },\n refresh: () => source.refresh({ force: true }),\n current: source.current,\n }\n}\n","/**\n * Surface-scoped profile overlay — the seam letting any product page (a\n * sequence editor, a brief composer, a dataset view) add MCP servers, a prompt\n * addendum, and permission tightening to the workspace agent profile for turns\n * initiated FROM that surface, without the chat orchestrator knowing any\n * surface's specifics. The orchestrator resolves `(kind, ctx)` through a\n * registry the REQUEST HANDLER constructs per request (construction is a Map\n * build — cheap) and merges the result into the base profile it was about to\n * send to the sandbox. Per-request construction is the trust mechanism, not an\n * optimization target: each `build()` closes over server-trusted request state\n * (env bindings, secrets, the AUTHENTICATED user/workspace), which on Workers\n * exists only per request — a startup-built registry would force identity\n * through the untrusted client `ctx`.\n *\n * SECURITY INVARIANT: the surface `kind` and the ids inside `ctx` arrive on\n * the client request and are pure ROUTING data — never trusted content, never\n * identity. Identity comes from the closure (see above). The registered\n * `build()` runs server-side only: it validates the routing ids against the\n * product's access control, then mints its own URLs from server configuration\n * (`buildHttpMcpServer` in ../tools). A client can therefore never inject an\n * arbitrary MCP url, header, or credential into the agent profile: the\n * overlay's `mcp` values are typed as {@link SurfaceMcpServer} (= the\n * server-built `AppToolMcpServer` entry shape), and only build() constructs\n * them.\n *\n * The credential itself never appears in the overlay. Since the tagged-config\n * contract (`agent-interface` 0.38.0) the `Authorization` header is a\n * `secret-ref` naming a box-environment variable, which the sandbox resolves\n * privately; `build()` supplies that key NAME from server configuration and the\n * product writes the value through `SandboxRuntimeConfig.env` at creation or\n * refreshes it through `SandboxRuntimeConfig.runtimeEnv` before retained-box\n * bootstrap. The value remains workspace-scoped because every member and turn\n * shares the box; runtime renewal does not create a per-user secret channel.\n */\n\nimport type { AppToolMcpServer } from '../tools/mcp'\n\n/** Sandbox permission posture values, ranked deny > ask > allow for merging. */\nexport type SurfacePermissionValue = 'allow' | 'ask' | 'deny'\n\n/** The only MCP entry shape an overlay may carry: the server-built bridge\n * entry from ../tools/mcp (transport, url, headers, and capability token all\n * assembled server-side). The alias exists so overlay authors reach for the\n * builders in ../tools rather than hand-rolling `{ url: ctx.url }` shapes\n * that would let request data become a dialable endpoint. */\nexport type SurfaceMcpServer = AppToolMcpServer\n\n/** What one surface contributes to the agent profile for a single turn. */\nexport interface SurfaceOverlay {\n /** MCP servers to mount for this turn, keyed by tool-routing name. Names\n * must not collide with the base profile's — see {@link mergeSurfaceOverlay}. */\n mcp?: Record<string, SurfaceMcpServer>\n /** Appended to the base system-prompt addendum with a blank-line separator. */\n promptAddendum?: string\n /** Per-key posture the surface wants for its turns. Merging is monotone\n * fail-closed: the stricter of base/overlay wins, so a surface can tighten\n * the workspace posture but never relax it. */\n permissions?: Record<string, SurfacePermissionValue>\n}\n\n/**\n * One registered surface kind. `TCtx` is the shape build() expects — a CLAIM\n * about the client payload, not a guarantee: the registry hands build() the\n * request's `ctx` unvalidated, so build() must treat every field as an\n * untrusted id (resolve it through access control that throws on a bad or\n * foreign id) before minting anything from it.\n */\nexport interface SurfaceKindDefinition<TCtx> {\n kind: string\n build: (ctx: TCtx) => SurfaceOverlay | Promise<SurfaceOverlay>\n}\n\n/** The variance-erased form a registry accepts (`build` is contravariant in\n * `TCtx`, so every concrete definition is assignable to this). */\nexport type AnySurfaceKind = SurfaceKindDefinition<never>\n\n/**\n * Declare one surface kind. The `kind` string is the client-visible routing\n * key (e.g. `'sequences'`); `build` is the server-side factory that turns a\n * validated ctx into the overlay for one turn.\n */\nexport function defineSurfaceKind<TCtx>(opts: {\n kind: string\n build: (ctx: TCtx) => SurfaceOverlay | Promise<SurfaceOverlay>\n}): SurfaceKindDefinition<TCtx> {\n if (typeof opts.kind !== 'string' || opts.kind.length === 0 || /\\s/.test(opts.kind)) {\n throw new Error(`surface kind must be a non-empty string without whitespace (got ${JSON.stringify(opts.kind)})`)\n }\n if (typeof opts.build !== 'function') {\n throw new Error(`surface kind '${opts.kind}' requires a build function`)\n }\n return { kind: opts.kind, build: opts.build }\n}\n\n/** Resolve and build the overlay for a given surface kind within a turn context */\nexport interface SurfaceRegistry {\n /** Build the overlay for one turn. Throws on an unknown kind — an unknown\n * surface is a routing bug (client and server registries drifted), and\n * silently returning an empty overlay would strip the surface's tools from\n * the turn with no signal anywhere. Build errors propagate unwrapped. */\n resolve(kind: string, ctx: unknown): Promise<SurfaceOverlay>\n}\n\n/**\n * Assemble the product's surface registry from its registered kinds. Duplicate\n * kinds throw at construction: two builders behind one routing key would make\n * the mounted toolset depend on registration order.\n */\nexport function createSurfaceRegistry(kinds: readonly AnySurfaceKind[]): SurfaceRegistry {\n const byKind = new Map<string, AnySurfaceKind>()\n for (const definition of kinds) {\n if (byKind.has(definition.kind)) {\n throw new Error(`duplicate surface kind '${definition.kind}' — each kind must be registered exactly once`)\n }\n byKind.set(definition.kind, definition)\n }\n\n return {\n async resolve(kind, ctx) {\n const definition = byKind.get(kind)\n if (!definition) {\n const known = [...byKind.keys()].join(', ') || '(none)'\n throw new Error(\n `unknown surface kind '${kind}' — registered kinds: ${known}. ` +\n 'An unknown surface is a routing bug: register the kind via defineSurfaceKind before clients can reference it.',\n )\n }\n // The trust boundary where static ctx typing ends: the request payload is\n // handed to build() as-is, and build() validates it (see SurfaceKindDefinition).\n const overlay = await definition.build(ctx as never)\n assertSurfaceOverlay(overlay, `surface kind '${kind}'`)\n return overlay\n },\n }\n}\n\n/** Base-profile slice the merge reads/writes. Real callers pass their full\n * profile object; every field outside this slice passes through untouched. */\nexport interface SurfaceMergeBase {\n mcp?: Record<string, unknown>\n systemPromptAddendum?: string\n permissions?: Record<string, SurfacePermissionValue>\n}\n\nconst PERMISSION_SEVERITY: Record<SurfacePermissionValue, number> = { allow: 0, ask: 1, deny: 2 }\n\n/**\n * Merge one surface overlay into a base profile, returning a new object\n * (the base is never mutated; untouched nested records are shared by\n * reference).\n *\n * - `mcp`: overlay servers are added under their own names. A name already\n * present on the base THROWS — a collision is two servers claiming one\n * routing name, and renaming either silently would corrupt tool routing for\n * whichever caller expected the original binding.\n * - `systemPromptAddendum`: the overlay's `promptAddendum` appends after a\n * blank-line separator (no separator when the base has no addendum).\n * - `permissions`: per key the STRICTER value wins (deny > ask > allow). A\n * surface can tighten the base posture for its turns; a base 'deny' survives\n * any overlay.\n */\nexport function mergeSurfaceOverlay<TBase extends SurfaceMergeBase>(\n base: TBase,\n overlay: SurfaceOverlay,\n): TBase & SurfaceMergeBase {\n assertSurfaceOverlay(overlay, 'surface overlay')\n const merged: SurfaceMergeBase = { ...base }\n\n if (overlay.mcp && Object.keys(overlay.mcp).length > 0) {\n const baseMcp = base.mcp ?? {}\n const collisions = Object.keys(overlay.mcp).filter((name) => name in baseMcp)\n if (collisions.length > 0) {\n throw new Error(\n `surface overlay MCP name collision: ${collisions.map((n) => `'${n}'`).join(', ')} already exist on the base profile. ` +\n 'Two servers cannot claim one name — give the surface server a distinct name.',\n )\n }\n merged.mcp = { ...baseMcp, ...overlay.mcp }\n }\n\n if (overlay.promptAddendum !== undefined) {\n merged.systemPromptAddendum = base.systemPromptAddendum\n ? `${base.systemPromptAddendum}\\n\\n${overlay.promptAddendum}`\n : overlay.promptAddendum\n }\n\n if (overlay.permissions && Object.keys(overlay.permissions).length > 0) {\n const permissions: Record<string, SurfacePermissionValue> = { ...(base.permissions ?? {}) }\n for (const [key, value] of Object.entries(overlay.permissions)) {\n const existing = permissions[key]\n permissions[key] =\n existing === undefined || PERMISSION_SEVERITY[value] > PERMISSION_SEVERITY[existing] ? value : existing\n }\n merged.permissions = permissions\n }\n\n // merged began as a shallow copy of base; only the three slice fields were\n // replaced, so the intersection type is the true shape.\n return merged as TBase & SurfaceMergeBase\n}\n\n/** Reject overlays a build() (or hand-rolled caller) malformed, with the exact\n * field named: a relative MCP url, a blank addendum, or an off-vocabulary\n * permission would otherwise surface only as an opaque sandbox failure. */\nfunction assertSurfaceOverlay(overlay: SurfaceOverlay, label: string): void {\n if (overlay.promptAddendum !== undefined) {\n if (typeof overlay.promptAddendum !== 'string' || overlay.promptAddendum.trim().length === 0) {\n throw new Error(`${label}: promptAddendum must be a non-blank string when provided`)\n }\n }\n if (overlay.mcp !== undefined) {\n for (const [name, server] of Object.entries(overlay.mcp)) {\n if (name.trim().length === 0) throw new Error(`${label}: MCP server names must be non-empty`)\n if (server.transport !== 'http') {\n throw new Error(`${label}: MCP server '${name}' must use transport 'http' (got ${JSON.stringify((server as { transport?: unknown }).transport)})`)\n }\n let parsed: URL\n try {\n parsed = new URL(server.url)\n } catch {\n throw new Error(`${label}: MCP server '${name}' url must be an absolute URL (got ${JSON.stringify(server.url)})`)\n }\n if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {\n throw new Error(`${label}: MCP server '${name}' url must be http(s) (got ${JSON.stringify(server.url)})`)\n }\n }\n }\n if (overlay.permissions !== undefined) {\n for (const [key, value] of Object.entries(overlay.permissions)) {\n if (!(value in PERMISSION_SEVERITY)) {\n throw new Error(`${label}: permission '${key}' must be 'allow' | 'ask' | 'deny' (got ${JSON.stringify(value)})`)\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA;AAAA,EACE;AAAA,OAGK;AAkBA,SAAS,wBAAwB,QAAoD;AAC1F,QAAM,SAAS,4BAA4B,MAAM;AACjD,SAAO;AAAA,IACL,MAAM,eAAe,MAAM;AACzB,aAAO,EAAE,GAAG,MAAM,cAAc,MAAM,OAAO,QAAQ,KAAK,YAAY,EAAE;AAAA,IAC1E;AAAA,IACA,SAAS,MA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AQ,GAAG,GAAG;AACxD,UAAI,KAAK,KAAK,EAAE,WAAW,EAAG,OAAM,IAAI,MAAM,GAAG,KAAK,sCAAsC;AAC5F,UAAI,OAAO,cAAc,QAAQ;AAC/B,cAAM,IAAI,MAAM,GAAG,KAAK,iBAAiB,IAAI,oCAAoC,KAAK,UAAW,OAAmC,SAAS,CAAC,GAAG;AAAA,MACnJ;AACA,UAAI;AACJ,UAAI;AACF,iBAAS,IAAI,IAAI,OAAO,GAAG;AAAA,MAC7B,QAAQ;AACN,cAAM,IAAI,MAAM,GAAG,KAAK,iBAAiB,IAAI,sCAAsC,KAAK,UAAU,OAAO,GAAG,CAAC,GAAG;AAAA,MAClH;AACA,UAAI,OAAO,aAAa,WAAW,OAAO,aAAa,UAAU;AAC/D,cAAM,IAAI,MAAM,GAAG,KAAK,iBAAiB,IAAI,8BAA8B,KAAK,UAAU,OAAO,GAAG,CAAC,GAAG;AAAA,MAC1G;AAAA,IACF;AAAA,EACF;AACA,MAAI,QAAQ,gBAAgB,QAAW;AACrC,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,QAAQ,WAAW,GAAG;AAC9D,UAAI,EAAE,SAAS,sBAAsB;AACnC,cAAM,IAAI,MAAM,GAAG,KAAK,iBAAiB,GAAG,2CAA2C,KAAK,UAAU,KAAK,CAAC,GAAG;AAAA,MACjH;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/runtime/loop.d.ts
CHANGED
|
@@ -55,6 +55,10 @@ export interface OpenAIStreamChunk {
|
|
|
55
55
|
usage?: {
|
|
56
56
|
prompt_tokens?: number;
|
|
57
57
|
completion_tokens?: number;
|
|
58
|
+
/** Prompt tokens the provider served from its prompt cache (Gemini implicit caching, OpenAI, Anthropic through the Router). */
|
|
59
|
+
prompt_tokens_details?: {
|
|
60
|
+
cached_tokens?: number | null;
|
|
61
|
+
} | null;
|
|
58
62
|
} | null;
|
|
59
63
|
}
|
|
60
64
|
/**
|
|
@@ -107,6 +107,7 @@ export type RouterTurnEvent = {
|
|
|
107
107
|
type: 'usage';
|
|
108
108
|
promptTokens: number;
|
|
109
109
|
completionTokens: number;
|
|
110
|
+
cachedPromptTokens?: number;
|
|
110
111
|
} | ({
|
|
111
112
|
type: 'tool_event';
|
|
112
113
|
} & RouterTurnToolEvent);
|
|
@@ -132,11 +133,13 @@ export interface RouterTurnOutcome {
|
|
|
132
133
|
toolName: string;
|
|
133
134
|
ok: boolean;
|
|
134
135
|
}>;
|
|
135
|
-
/** Token use summed over every model call in the turn, as the router reported it.
|
|
136
|
+
/** Token use summed over every model call in the turn, as the router reported it. `cachedPromptTokens` are the
|
|
137
|
+
* prompt tokens the provider served from its prompt cache; absent when no call reported them. */
|
|
136
138
|
usage: {
|
|
137
139
|
promptTokens: number;
|
|
138
140
|
completionTokens: number;
|
|
139
141
|
modelCalls: number;
|
|
142
|
+
cachedPromptTokens?: number;
|
|
140
143
|
};
|
|
141
144
|
/** Reasoning the turn streamed (deltas and characters). Zero when the model sent none; absent when no model was called. */
|
|
142
145
|
reasoning?: {
|
|
@@ -303,24 +306,52 @@ export interface RouterTurnOptions {
|
|
|
303
306
|
}
|
|
304
307
|
/** OpenAI-compatible function names allow only `[A-Za-z0-9_-]{1,64}`; app tool names often use dots. */
|
|
305
308
|
export declare function routerFunctionName(name: string): string;
|
|
309
|
+
export interface RouterTurnPromptSections {
|
|
310
|
+
/** Every section that is the same on each turn of a workspace, first, so the bytes repeat turn after turn. */
|
|
311
|
+
prefix: string;
|
|
312
|
+
/** What this turn adds: its `context`. Empty when there is none. */
|
|
313
|
+
tail: string;
|
|
314
|
+
/** `prefix` then `tail`: the system prompt the model reads. */
|
|
315
|
+
text: string;
|
|
316
|
+
}
|
|
317
|
+
export interface RouterTurnPromptOptions {
|
|
318
|
+
/** Sections the same on every turn of a workspace (skills, tool guidance, catalogs, references). They go in the
|
|
319
|
+
* prefix, after the profile's prompt, so a provider's prompt cache serves them. */
|
|
320
|
+
stable?: readonly string[];
|
|
321
|
+
/** This turn's own sections (the clock, the board, what changed, ids). They go last, after every stable byte. */
|
|
322
|
+
context?: readonly string[];
|
|
323
|
+
toolNames?: readonly string[];
|
|
324
|
+
/** Knowledge files every turn carries; see {@link turnKnowledgeInstructions}. They change only when the workspace
|
|
325
|
+
* edits them, so they close the prefix. */
|
|
326
|
+
knowledge?: {
|
|
327
|
+
files: readonly TurnKnowledgeFile[];
|
|
328
|
+
readTool?: string;
|
|
329
|
+
};
|
|
330
|
+
}
|
|
306
331
|
/**
|
|
307
|
-
* The lean system prompt for a Router turn
|
|
308
|
-
*
|
|
309
|
-
* names the
|
|
332
|
+
* The lean system prompt for a Router turn, split where its bytes stop repeating. The prefix holds the profile's
|
|
333
|
+
* system prompt, appended prompt and instructions, the reply-language rule, the caller's `stable` sections and the
|
|
334
|
+
* knowledge files; the tail holds the turn's `context`. Tool names are rewritten to the function names the model
|
|
335
|
+
* actually calls.
|
|
336
|
+
*
|
|
337
|
+
* A provider serves a repeated prompt prefix from its cache: through the Router, Gemini served 38,685 of
|
|
338
|
+
* 40,734 prompt tokens from cache on each repeat of a stable 150 kB prefix, and none when a timestamp came first
|
|
339
|
+
* (2026-10-22). One per-turn byte early in the prompt therefore costs the whole prompt on every turn, so nothing
|
|
340
|
+
* per-turn belongs in `stable` or the profile's prompt.
|
|
310
341
|
*/
|
|
311
|
-
export declare function
|
|
342
|
+
export declare function composeRouterTurnPromptSections(profile: {
|
|
312
343
|
prompt?: {
|
|
313
344
|
systemPrompt?: string;
|
|
314
345
|
appendSystemPrompt?: string;
|
|
315
346
|
instructions?: readonly string[];
|
|
316
347
|
};
|
|
317
|
-
}, options?:
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
348
|
+
}, options?: RouterTurnPromptOptions): RouterTurnPromptSections;
|
|
349
|
+
/** The system prompt {@link composeRouterTurnPromptSections} composes, as one string. */
|
|
350
|
+
export declare function composeRouterTurnPrompt(profile: {
|
|
351
|
+
prompt?: {
|
|
352
|
+
systemPrompt?: string;
|
|
353
|
+
appendSystemPrompt?: string;
|
|
354
|
+
instructions?: readonly string[];
|
|
324
355
|
};
|
|
325
|
-
}): string;
|
|
356
|
+
}, options?: RouterTurnPromptOptions): string;
|
|
326
357
|
export declare function runRouterTurn(options: RouterTurnOptions): Promise<RouterTurnOutcome>;
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
asksForLanguage,
|
|
4
4
|
budgetTurnKnowledge,
|
|
5
5
|
composeRouterTurnPrompt,
|
|
6
|
+
composeRouterTurnPromptSections,
|
|
6
7
|
placeRouterTurn,
|
|
7
8
|
replyLanguageInstruction,
|
|
8
9
|
routerFunctionName,
|
|
@@ -11,16 +12,17 @@ import {
|
|
|
11
12
|
turnKnowledgeInstructions,
|
|
12
13
|
workspaceKnowledgeForTurn,
|
|
13
14
|
workspaceTurnCheckpoints
|
|
14
|
-
} from "../chunk-
|
|
15
|
-
import "../chunk-
|
|
15
|
+
} from "../chunk-QTWTZYXC.js";
|
|
16
|
+
import "../chunk-UFQM46NV.js";
|
|
16
17
|
import "../chunk-D6UJEOZQ.js";
|
|
17
18
|
import "../chunk-AMUXRAUO.js";
|
|
18
|
-
import "../chunk-
|
|
19
|
+
import "../chunk-ORQD4AUO.js";
|
|
19
20
|
export {
|
|
20
21
|
DURABLE_HOP_BUDGET_MS,
|
|
21
22
|
asksForLanguage,
|
|
22
23
|
budgetTurnKnowledge,
|
|
23
24
|
composeRouterTurnPrompt,
|
|
25
|
+
composeRouterTurnPromptSections,
|
|
24
26
|
placeRouterTurn,
|
|
25
27
|
replyLanguageInstruction,
|
|
26
28
|
routerFunctionName,
|
package/dist/sandbox/index.js
CHANGED
|
@@ -100,7 +100,7 @@ import {
|
|
|
100
100
|
warmBinOf,
|
|
101
101
|
warmWeekdayOf,
|
|
102
102
|
writeProfileFilesToBox
|
|
103
|
-
} from "../chunk-
|
|
103
|
+
} from "../chunk-CFGBGIRK.js";
|
|
104
104
|
import {
|
|
105
105
|
EGRESS_PROXY_RECOVERY_PHASE,
|
|
106
106
|
EGRESS_PROXY_RECOVERY_REQUIRED,
|
|
@@ -141,17 +141,17 @@ import {
|
|
|
141
141
|
} from "../chunk-4LBCTFBP.js";
|
|
142
142
|
import "../chunk-FPNZMIAW.js";
|
|
143
143
|
import "../chunk-LWSJK546.js";
|
|
144
|
-
import "../chunk-
|
|
144
|
+
import "../chunk-5BJHKQ33.js";
|
|
145
145
|
import "../chunk-6A7MYOUI.js";
|
|
146
146
|
import "../chunk-O7UX55EU.js";
|
|
147
|
-
import "../chunk-
|
|
147
|
+
import "../chunk-XEAZWJ3W.js";
|
|
148
148
|
import "../chunk-S5SRJJQG.js";
|
|
149
|
-
import "../chunk-
|
|
149
|
+
import "../chunk-7TZA2TAM.js";
|
|
150
150
|
import "../chunk-UGWQLQDS.js";
|
|
151
|
-
import "../chunk-
|
|
152
|
-
import "../chunk-
|
|
151
|
+
import "../chunk-WSQFNMIA.js";
|
|
152
|
+
import "../chunk-UFQM46NV.js";
|
|
153
153
|
import "../chunk-D6UJEOZQ.js";
|
|
154
|
-
import "../chunk-
|
|
154
|
+
import "../chunk-ORQD4AUO.js";
|
|
155
155
|
export {
|
|
156
156
|
DEFAULT_ESCALATION_TOOLS,
|
|
157
157
|
DEFAULT_FOREGROUND_PROVISION_CLAIM_TTL_SECONDS,
|
package/dist/tools/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
outcomeStatus,
|
|
6
6
|
resolveToolCapabilities,
|
|
7
7
|
restrictTaxonomy
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-5BJHKQ33.js";
|
|
9
9
|
import {
|
|
10
10
|
DEFAULT_APP_TOOL_PATHS,
|
|
11
11
|
DEFAULT_HEADER_NAMES,
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
verifyCapabilityToken,
|
|
25
25
|
verifyExpiringCapabilityToken
|
|
26
26
|
} from "../chunk-O7UX55EU.js";
|
|
27
|
-
import "../chunk-
|
|
27
|
+
import "../chunk-XEAZWJ3W.js";
|
|
28
28
|
import "../chunk-S5SRJJQG.js";
|
|
29
29
|
import {
|
|
30
30
|
APP_TOOL_NAMES,
|
|
@@ -33,11 +33,11 @@ import {
|
|
|
33
33
|
defineAppTool,
|
|
34
34
|
findCustomTool,
|
|
35
35
|
isAppToolName
|
|
36
|
-
} from "../chunk-
|
|
36
|
+
} from "../chunk-7TZA2TAM.js";
|
|
37
37
|
import "../chunk-UGWQLQDS.js";
|
|
38
38
|
import {
|
|
39
39
|
ToolInputError
|
|
40
|
-
} from "../chunk-
|
|
40
|
+
} from "../chunk-WSQFNMIA.js";
|
|
41
41
|
export {
|
|
42
42
|
APP_TOOL_NAMES,
|
|
43
43
|
DEFAULT_APP_TOOL_PATHS,
|
package/dist/turn-trace/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
nextCallIndex,
|
|
3
3
|
tracedModelFetch
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-UFQM46NV.js";
|
|
5
5
|
import {
|
|
6
6
|
TURN_SPAN_KINDS,
|
|
7
7
|
buildTurnTraceOtelSpans,
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
serverTimingAttrs,
|
|
16
16
|
summarizeTurnSpans,
|
|
17
17
|
turnTraceId
|
|
18
|
-
} from "../chunk-
|
|
18
|
+
} from "../chunk-ORQD4AUO.js";
|
|
19
19
|
export {
|
|
20
20
|
TURN_SPAN_KINDS,
|
|
21
21
|
buildTurnTraceOtelSpans,
|
|
@@ -67,6 +67,13 @@ export interface TurnTraceSummary {
|
|
|
67
67
|
firstVisibleMs?: number;
|
|
68
68
|
/** D1 round trips in the turn scope, when its binding is instrumented. */
|
|
69
69
|
d1Queries?: number;
|
|
70
|
+
/** From the request to the first model request: the wait the app owns before the model can start. */
|
|
71
|
+
dispatchMs?: number;
|
|
72
|
+
/** Each `admission.*` span's duration by its name after `admission.`, the split of the wait before the turn opens. */
|
|
73
|
+
admission?: Record<string, number>;
|
|
74
|
+
/** Prompt tokens over every model call, and how many of them the provider served from its prompt cache. */
|
|
75
|
+
inputTokens?: number;
|
|
76
|
+
cachedInputTokens?: number;
|
|
70
77
|
}
|
|
71
78
|
export interface TurnTraceSnapshot {
|
|
72
79
|
traceId: string;
|
package/dist/web-react/index.js
CHANGED
|
@@ -145,7 +145,7 @@ import {
|
|
|
145
145
|
withoutRecordGridCreated,
|
|
146
146
|
withoutRecordGridRemoved,
|
|
147
147
|
withoutRecordGridUpdate
|
|
148
|
-
} from "../chunk-
|
|
148
|
+
} from "../chunk-BYP54FMI.js";
|
|
149
149
|
import {
|
|
150
150
|
MENTION_PILL_CLASS
|
|
151
151
|
} from "../chunk-3HUFJ5LO.js";
|
|
@@ -181,7 +181,7 @@ import {
|
|
|
181
181
|
preloadWhenIdle,
|
|
182
182
|
useComposerAttachments,
|
|
183
183
|
useDictation
|
|
184
|
-
} from "../chunk-
|
|
184
|
+
} from "../chunk-WCXHXCER.js";
|
|
185
185
|
import "../chunk-L7MB2LLM.js";
|
|
186
186
|
import {
|
|
187
187
|
WorkspaceInitial,
|
|
@@ -245,7 +245,7 @@ import {
|
|
|
245
245
|
ALLOWED_ATTACHMENT_SNIFFED_MIMES,
|
|
246
246
|
ATTACHMENT_ACCEPT,
|
|
247
247
|
OOXML_SNIFFED_MIMES
|
|
248
|
-
} from "../chunk-
|
|
248
|
+
} from "../chunk-NHVSO47Q.js";
|
|
249
249
|
import "../chunk-FPNZMIAW.js";
|
|
250
250
|
import "../chunk-B7CL7ENS.js";
|
|
251
251
|
import "../chunk-PV33JZKV.js";
|
|
@@ -257,7 +257,7 @@ import {
|
|
|
257
257
|
isChatAttachmentPart,
|
|
258
258
|
mentionInputToPart,
|
|
259
259
|
mentionPartsFromMessageParts
|
|
260
|
-
} from "../chunk-
|
|
260
|
+
} from "../chunk-23JUSUUB.js";
|
|
261
261
|
import "../chunk-ZVEEWGDK.js";
|
|
262
262
|
import {
|
|
263
263
|
DISPATCH_MAX_MEDIA_PARTS,
|
|
@@ -281,7 +281,7 @@ import {
|
|
|
281
281
|
mediaTypeForMentionPath,
|
|
282
282
|
mentionKindForPath,
|
|
283
283
|
settleTurnResponse
|
|
284
|
-
} from "../chunk-
|
|
284
|
+
} from "../chunk-5TSRFF5W.js";
|
|
285
285
|
import "../chunk-TXD5HXLE.js";
|
|
286
286
|
import {
|
|
287
287
|
attachmentPartKey
|
|
@@ -16,11 +16,11 @@ import {
|
|
|
16
16
|
} from "../chunk-3NVVBQ2U.js";
|
|
17
17
|
import {
|
|
18
18
|
defineAppTool
|
|
19
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-7TZA2TAM.js";
|
|
20
20
|
import "../chunk-UGWQLQDS.js";
|
|
21
21
|
import {
|
|
22
22
|
ToolInputError
|
|
23
|
-
} from "../chunk-
|
|
23
|
+
} from "../chunk-WSQFNMIA.js";
|
|
24
24
|
import {
|
|
25
25
|
isWorkProductStatus,
|
|
26
26
|
parseAgentCheckInput,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangle-network/agent-app",
|
|
3
|
-
"version": "0.60.
|
|
3
|
+
"version": "0.60.248",
|
|
4
4
|
"packageManager": "pnpm@11.24.0",
|
|
5
5
|
"description": "Build agent applications with typed chat, tools, sandboxes, integrations, billing, and evaluation.",
|
|
6
6
|
"keywords": [
|
|
@@ -717,7 +717,7 @@
|
|
|
717
717
|
"@tangle-network/hub-sdk": "0.30.10",
|
|
718
718
|
"@tangle-network/sandbox": "0.63.10",
|
|
719
719
|
"@tangle-network/sandbox-ui": "0.136.1",
|
|
720
|
-
"@tangle-network/ui": "11.
|
|
720
|
+
"@tangle-network/ui": "11.41.0",
|
|
721
721
|
"@testing-library/dom": "^10.4.1",
|
|
722
722
|
"@testing-library/react": "^16.3.3",
|
|
723
723
|
"@testing-library/user-event": "^14.6.6",
|