@standardagents/agentbuilder-template 0.43.1 → 0.44.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -42,6 +42,27 @@ the agent relies on it. Authentication, billing, deployment, and branded UI
42
42
  services may remain external as long as they are not required for the packed
43
43
  agent's core execution semantics.
44
44
 
45
+ ## Packaging and Definition Visibility
46
+
47
+ The packer follows side \`subagents\` relationships and includes child agents
48
+ and their dependencies. This includes hidden children and relationships with
49
+ \`as\`. The package includes referenced handlers and exports a \`handlers\`
50
+ registry. The pack and unpack dialogs list handlers. Unpack analysis reports an agent\u2019s handlers and side \`subagents\` relationships.
51
+ In the pack dialog, a handler defaults to extract. Shared handlers default to copy. Extract removes
52
+ the local file; copy keeps it. Dependencies reached by another local agent,
53
+ including through its children, default to copy.
54
+
55
+ The runtime discovers packages in \`node_modules\` and \`agents/packed/\`.
56
+ It loads definitions from lazy registries and \`__meta\` exported by each
57
+ package entry module. A malformed \`package.json\` or missing or invalid
58
+ \`__meta\` produces a warning and the runtime skips that package.
59
+
60
+ \`ThreadState.loadModel\`, \`loadPrompt\`, and \`loadAgent\` enforce package
61
+ visibility. Global code can load unpacked definitions and packed entry agents.
62
+ Packed code can load its own definitions and other packages' entry agents.
63
+ A packed model cannot fall back to a host model with the same short name.
64
+ A refused load returns the same not-found error as a missing definition.
65
+
45
66
  ## How Components Compose
46
67
 
47
68
  ### Basic Flow
@@ -147,7 +168,9 @@ interface ThreadState {
147
168
  runtimeStreams?: RuntimeStreams; // Optional live execution-host byte streams
148
169
 
149
170
  // Methods
150
- getMessages(options?): Promise<MessagesResult>; // Get conversation history
171
+ getMessages(options?): Promise<MessagesResult>; // Get conversation history, newest first by default
172
+ getMessage(id): Promise<Message | null>; // Find a persisted message by ID
173
+ updateMessage(id, updates): Promise<Message>; // Update a persisted message
151
174
  injectMessage(input): Promise<Message>; // Add message to thread
152
175
  queueMessage(input): Promise<void>; // Queue message for next step
153
176
  emit(event, data): void; // Broadcast a custom event to connected thread clients
@@ -199,7 +222,7 @@ what was sent (\`request\`), what came back (\`response\` or \`error\`), and its
199
222
  execution; oversized fields are truncated (name 120 chars, message and error
200
223
  4 KiB, data JSON 16 KiB, request and response JSON 64 KiB each).
201
224
 
202
- \`runCode\` has no implicit access to thread state, filesystem, network, timers, or host globals. Bridge only the exact capabilities needed through \`imports\` or \`globals\`; use \`modules\` for local relative ES modules; use \`execute\` to select the export and args to run. \`modules\` keys are graph-root relative paths; entry-source imports resolve from \`filename\` when supplied, including \`../\` parent paths that stay inside the supplied graph. TypeScript input is accepted by default and erased before evaluation. In thread endpoints, \`runCode\` is forwarded into the thread Durable Object; pass plain transferable options there and keep function-backed bridges in tools or in-thread execution contexts.
225
+ \`runCode\` has no implicit access to thread state, filesystem, network, timers, or host globals. Bridge only the exact capabilities needed through \`imports\` or \`globals\`; use \`modules\` for local relative ES modules; use \`execute\` to select the export and args to run. \`modules\` keys are graph-root relative paths; entry-source imports resolve from \`filename\` when supplied, including \`../\` parent paths that stay inside the supplied graph. TypeScript input is accepted by default and erased before evaluation. In thread endpoints, \`runCode\` forwards functions in imports, globals, and execution arguments as callable proxies. Call \`run.terminate(reason)\` to stop the sandbox. A caller disconnect also stops the run. When \`report\` is supplied, the host receives reports during the run and \`run.reports\` updates as reports arrive.
203
226
 
204
227
  ## Subagents
205
228
 
@@ -575,6 +598,7 @@ Prompts define system instructions, model selection, and available tools for LLM
575
598
  | \`env\` | \`Record<string, string>\` | No | Prompt-level default values for variables |
576
599
  | \`hooks\` | \`string[]\` | No | Hook IDs to run for this prompt (overrides agent hooks) |
577
600
  | \`reasoning\` | \`ReasoningConfig\` | No | Extended thinking configuration |
601
+ | \`providerOptions\` | \`Record<string, unknown>\` | No | Provider-specific request options |
578
602
 
579
603
  ## Basic Example
580
604
 
@@ -611,6 +635,8 @@ export default definePrompt({
611
635
  });
612
636
  \`\`\`
613
637
 
638
+ A circular prompt include raises an error that names the include chain. A prompt can include the same partial through different paths.
639
+
614
640
  \`type: 'env'\` inserts a resolved thread variable value. Use this only for non-secret values that are safe to expose to the LLM.
615
641
 
616
642
  The sandboxed coding prompt declares \`HTTP_HOST\` as a text variable and injects its resolved value with a structured \`{ type: 'env', property: 'HTTP_HOST' }\` prompt part. Its URL helper uses that value as the origin for files exposed from the thread \`public/\` directory and endpoints exposed from the thread \`api/\` directory. Public URLs should usually omit extensions; extensionless public paths resolve \`.html\`, then \`.js\`, then \`.ts\`, then matching \`index\` files in the same order. Browser pages should reference only public files, \`api/\` endpoints, or absolute external URLs, using relative asset URLs like \`./app\` and \`./api/todos\`; private \`src/\` files are not served directly. Public \`.ts\` files are transformed to browser JavaScript and are not server endpoints. Server-side endpoints live under the thread filesystem \`api/\` directory, and the \`api/\` directory name stays in the public URL: \`api/todo.ts\` is \`/api/threads/{threadId}/api/todo\`, while \`api/todo.ts\` is not \`/api/threads/{threadId}/todo\` or \`/api/threads/{threadId}/todos\`. Endpoint files default-export a function that accepts \`Request\` and returns \`Response\` or \`Promise<Response>\`. Endpoint code can import \`fetch\`, \`fs\`, and \`storage\`, and can import private helpers with relative paths such as \`../src/todo.ts\`. When the coding agent creates a site, page, or endpoint, it should call \`get_public_url\` with the created file path and use the returned URL.
@@ -665,13 +691,26 @@ sideA: {
665
691
  For a prompt-backed side with non-hidden relationships, the runtime automatically injects three lifecycle tools scoped to that side's declarations:
666
692
 
667
693
  - \`subagents\` \u2014 pull-based visibility: returns the registry snapshot (reference, relationship name, agent name, status, initial arguments, creation time). Call it before \`subagent_create\` so existing instances are reused rather than duplicated.
668
- - \`subagent_create\` \u2014 creates (or continues) an instance. Its \`agent\` argument enumerates the side's enabled relationship *names* (\`as\`, defaulting to \`agent\`), never internal agent identifiers. It requires a non-empty \`name\` for the spawned instance; AgentBuilder stores that as a \`name:<value>\` thread tag for human-friendly labels.
694
+ - \`subagent_create\` \u2014 creates (or continues) an instance. Its \`agent\` argument enumerates the side's enabled relationship *names* (\`as\`, defaulting to the unqualified part of \`agent\`), never internal agent identifiers. It requires a non-empty \`name\` for the spawned instance; AgentBuilder stores that as a \`name:<value>\` thread tag for human-friendly labels.
669
695
  - \`subagent_message\` \u2014 queues a message to an existing instance by reference.
670
696
 
671
697
  These three names are reserved; a relationship \`as\` that collides with them (or with any other tool name) is a definition-time error.
672
698
 
673
699
  \`subagent_create.arguments\` is shaped by the \`requiredSchema\` of the receiving child's side A prompt (parent traffic enters the child in the side B perspective, \`role: 'user'\`, so side A acts on it exactly as for an external caller). AgentBuilder validates and persists those arguments for the life of the child thread, exposes them as \`ThreadState.arguments\` and prompt variables to **both** child sides, and rehydrates them on every later activation. Missing required arguments fail creation with a structured \`subagent_arguments_required\` error.
674
700
 
701
+ \`subagent_create\` accepts \`agent\`, \`name\`, and \`arguments\`.
702
+ The relationship maps its initial message and attachments from \`arguments\`.
703
+ Create-or-continue applies the same mappings to the existing child.
704
+ Without a mapped message value, Builder uses the optional top-level \`message\` before falling back to serialized arguments.
705
+ Empty arguments produce the JSON activation payload {}.
706
+ The relationship contributes missing message and attachment fields to the model-facing argument schema.
707
+ The model-facing schema and runtime accept optional top-level \`message\` and \`attachments\`.
708
+ These fields are AgentBuilder extensions beyond Spec 0.2.0 Subagents \xA75 for existing callers such as Standard Code Mux.
709
+ Relationships should migrate to \`initUserMessageProperty\` and mapped \`arguments\`.
710
+ Strict providers may require these keys on the wire with null values to omit them.
711
+ Mapped arguments take precedence over these compatibility fields.
712
+ Relationship-only fields initialize messages without becoming persistent child arguments.
713
+
675
714
  Persistence is universal: every child instance is a persistent thread. Session end never terminates a child \u2014 a later \`subagent_message\` starts a new session with history intact; only explicit \`state.terminate()\` destroys an instance. \`blocking: true\` makes \`subagent_create\` await the child session's close and return its result; combined with \`maxInstances: 1\` and an existing instance it behaves as create-or-continue.
676
715
 
677
716
  If required scoped vars are missing, the runtime returns \`error_code: "subagent_env_required"\` with a temporary \`GET/POST /api/threads/:threadId/variables/:requestId\` endpoint in \`error_data.endpoint\`.
@@ -697,8 +736,16 @@ export default definePrompt({
697
736
  });
698
737
  \`\`\`
699
738
 
739
+ Provider options merge from model defaults to prompt overrides. Later values win.
740
+
700
741
  ## Extended Thinking (Reasoning)
701
742
 
743
+ A prompt can set \`reasoning.level\` from 0 to 100. An unset level uses the model's default. Level 0 disables reasoning when the model supports a disabling control. Otherwise, the provider selects the lowest reasoning setting. A model with no reasoning control receives no control. Each provider maps the level to the nearest option the model declares.
744
+
745
+ A prompt's \`reasoning.level\` replaces a native effort value in \`providerOptions\`. Other \`providerOptions\` keys remain. Without a level, \`providerOptions\` apply as provided. Native effort values in a model's \`providerOptions\` remain valid.
746
+
747
+ Saved prompt input with \`reasoning.effort\` fails validation. A published package prompt with \`reasoning.effort\` loads with a warning. The runtime ignores that field.
748
+
702
749
  Enable for complex reasoning tasks:
703
750
 
704
751
  \`\`\`typescript
@@ -708,7 +755,7 @@ export default definePrompt({
708
755
  model: 'heavy',
709
756
  prompt: 'Review the code thoroughly...',
710
757
  reasoning: {
711
- effort: 'high', // 'low' | 'medium' | 'high'
758
+ level: 100, // 0 to 100
712
759
  maxTokens: 16000, // Max thinking tokens
713
760
  exclude: true, // Don't include thinking in response
714
761
  },
@@ -719,7 +766,7 @@ export default definePrompt({
719
766
 
720
767
  \`\`\`typescript
721
768
  reasoning: {
722
- effort: 'low', // Can be 'low', 'medium', or 'high'
769
+ level: 33, // 0 to 100
723
770
  },
724
771
  \`\`\`
725
772
 
@@ -798,8 +845,8 @@ A side's configuration is discriminated by its backing: exactly one of \`human\`
798
845
  | \`label\` | \`string\` | No | Display name for this side |
799
846
  | \`subagents\` | \`SubagentRelationship[]\` | No | Side-owned child relationships (see Subagent Relationships below) |
800
847
  | \`stopOnResponse\` | \`boolean\` | No | Stop side turn on text response without tool calls (default: true) |
801
- | \`stopTool\` | \`string\` | No | Tool that stops this side's turn |
802
- | \`stopToolResponseProperty\` | \`string\` | No | Property to extract from stop tool result |
848
+ | \`stopTool\` | \`string\` | No | Tool that stops this side's turn when called, with or without \`stopToolResponseProperty\` |
849
+ | \`stopToolResponseProperty\` | \`string\` | No | Property to extract from the stop tool result. This option requires \`stopTool\`. |
803
850
  | \`maxSteps\` | \`number\` | No | Maximum step budget for this side |
804
851
  | \`sessionStop\` | \`SessionToolBinding\` | No | Terminal success lifecycle binding (object form only) |
805
852
  | \`sessionFail\` | \`SessionToolBinding\` | No | Terminal failure lifecycle binding (object form only) |
@@ -914,7 +961,7 @@ sideA: {
914
961
  \`\`\`
915
962
 
916
963
  - The owning side is where child traffic lands: completion, failure, and status messages arrive on the owning side's perspective. Parent\u2192child traffic enters in the child's side B perspective (\`role: 'user'\`), so the child's side A acts on it.
917
- - A relationship name (\`as\`, defaulting to \`agent\`) may appear on at most one side, must not collide with another tool name, and must not collide with the reserved lifecycle tool names \`subagents\`, \`subagent_create\`, \`subagent_message\`.
964
+ - A relationship name (\`as\`, defaulting to the unqualified part of \`agent\`) may appear on at most one side, must not collide with another tool name, and must not collide with the reserved lifecycle tool names \`subagents\`, \`subagent_create\`, \`subagent_message\`.
918
965
  - For a prompt-backed owning side, the runtime injects those lifecycle tools automatically. Handler-backed owning sides need no tool grant \u2014 handlers reach children through \`ThreadState\` directly.
919
966
  - **Persistence is universal**: every child instance is a persistent thread. Session end never terminates a thread; only explicit \`state.terminate()\` destroys an instance. \`blocking\` is purely a waiting style.
920
967
 
@@ -1202,6 +1249,10 @@ export default defineTool({
1202
1249
  });
1203
1250
  \`\`\`
1204
1251
 
1252
+ Tool variable definitions preserve \`scoped: true\`. A scoped variable blocks inheritance from the parent thread environment.
1253
+
1254
+ \`defineTool()\` preserves \`annotations\` unchanged.
1255
+
1205
1256
  ## Argument Schemas
1206
1257
 
1207
1258
  Tool args must be a top-level \`z.object(...)\`. Prefer explicit, bounded schemas made from strings, numbers, booleans, nulls, literals, enums, arrays, objects, optionals, nullables, and defaults. Avoid provider-visible recursive or open-ended schemas such as \`z.unknown()\`, \`z.any()\`, and \`z.object({}).catchall(...)\`; strict tool providers can reject the generated JSON Schema. If a tool needs arbitrary JSON input, accept it as a JSON string and parse it inside \`execute\`.
@@ -1247,9 +1298,8 @@ execute: async (state, args) => {
1247
1298
  // per-user personalization or entitlement checks. Null when user-less.
1248
1299
  const user = await state.user();
1249
1300
 
1250
- // Instance-GLOBAL Agent Skills library (agentskills.io SKILL.md format).
1251
- // Skills install once and are visible to every thread; load a skill's body
1252
- // only when it's applicable (progressive disclosure).
1301
+ // A thread sees its owner's skills and enabled shared skills.
1302
+ // Load a skill body when it applies. Mutations require an instance admin.
1253
1303
  const skills = await state.skills.list();
1254
1304
  const skill = await state.skills.get('pdf-processing');
1255
1305
  const script = await state.skills.readFile('pdf-processing', 'scripts/extract.py');
@@ -1271,7 +1321,7 @@ execute: async (state, args) => {
1271
1321
  }
1272
1322
  \`\`\`
1273
1323
 
1274
- Use \`state.runCode()\` instead of \`eval\` or \`new Function\` for model- or user-authored JavaScript/TypeScript. The sandbox starts with no ambient host capabilities; provide imports/globals explicitly, use \`modules\` for local relative ES modules, use \`execute\` to select an export and pass args, use \`report\` for streamed observations, and call \`run.terminate(reason)\` from your own timeout budget when needed. \`modules\` keys are graph-root relative paths; entry-source imports resolve from \`options.filename\` when supplied. Relative module imports may use \`./\` and \`../\` as long as they resolve within the supplied module graph. In thread endpoints, \`runCode\` is forwarded into the thread Durable Object; pass plain transferable option values there, and do function-backed bridges from tools or in-thread execution contexts.
1324
+ Use \`state.runCode()\` instead of \`eval\` or \`new Function\` for model- or user-authored JavaScript/TypeScript. The sandbox starts with no ambient host capabilities; provide imports/globals explicitly, use \`modules\` for local relative ES modules, use \`execute\` to select an export and pass args, use \`report\` for streamed observations, and call \`run.terminate(reason)\` from your own timeout budget when needed. \`modules\` keys are graph-root relative paths; entry-source imports resolve from \`options.filename\` when supplied. Relative module imports may use \`./\` and \`../\` as long as they resolve within the supplied module graph. In thread endpoints, \`runCode\` forwards functions in imports, globals, and execution arguments as callable proxies. Call \`run.terminate(reason)\` to stop the sandbox. A caller disconnect also stops the run. When \`report\` is supplied, the host receives reports during the run and \`run.reports\` updates as reports arrive.
1275
1325
 
1276
1326
  ### Optional Runtime Streams
1277
1327
 
@@ -1518,7 +1568,7 @@ Hooks intercept and modify agent execution at specific lifecycle points.
1518
1568
  | \`prefilter_llm_history\` | \`(state: ThreadState, messages: LLMMessage[]) => LLMMessage[]\` | Modify transformed provider messages before dispatch |
1519
1569
  | \`before_create_message\` | \`(state: ThreadState, message: Message) => Message\` | Modify message before database insert |
1520
1570
  | \`after_create_message\` | \`(state: ThreadState, message: Message) => void\` | Run logic after message created |
1521
- | \`before_update_message\` | \`(state: ThreadState, id: string, updates: Record) => Record\` | Modify updates before message update |
1571
+ | \`before_update_message\` | \`(state: ThreadState, id: string, updates: Record) => Record\` | Modify updates for a persisted message before its update |
1522
1572
  | \`after_update_message\` | \`(state: ThreadState, message: Message) => void\` | Run logic after message updated |
1523
1573
  | \`before_store_tool_result\` | \`(state: ThreadState, toolCall: HookToolCall, result: HookToolResult) => HookToolResult\` | Modify tool result before storage |
1524
1574
  | \`after_tool_call_success\` | \`(state: ThreadState, toolCall: HookToolCall, result: HookToolResult) => HookToolResult \\| null\` | Process successful tool execution |
@@ -1534,6 +1584,10 @@ first and \`HookExecutionContext\` last. The context source is prompt, agent, or
1534
1584
  child provenance; child provenance includes \`relationshipName\`, resolved
1535
1585
  \`agentName\`, and optional package signature.
1536
1586
 
1587
+ Packed thread hooks receive a \`ThreadState\` in their owning package namespace.
1588
+ Every hook can use \`state.loadPrompt('own')\` to load a package-local prompt.
1589
+ This includes \`before_create_message\`.
1590
+
1537
1591
  ## Creating a Hook
1538
1592
 
1539
1593
  Each hook file exports a default \`defineHook\` call with three properties:
@@ -1779,6 +1833,9 @@ var API_AGENTS_MD = `# Thread-Specific API Endpoints
1779
1833
 
1780
1834
  Define custom API endpoints that operate on specific threads with access to the thread's ThreadState.
1781
1835
 
1836
+ Unmatched thread endpoint paths return JSON with HTTP 404.
1837
+ A method without a matching endpoint route also returns HTTP 404.
1838
+
1782
1839
  ## File-Based Routing
1783
1840
 
1784
1841
  | File Pattern | HTTP Method | Route |
@@ -1850,10 +1907,16 @@ A public endpoint is reachable by anyone who has the URL \u2014 treat it like an
1850
1907
  internet-facing route: validate the path, reject early, and never echo
1851
1908
  private state to anonymous callers.
1852
1909
 
1853
- Note: \`state.execution\` is always \`null\` in endpoints since the thread is at rest. \`state.runCode()\` is available from endpoints and is forwarded into the thread runtime; pass plain transferable option values there, and do function-backed sandbox bridges from tools or in-thread execution contexts. \`state.emit(event, data)\` broadcasts a custom WebSocket event from endpoints as well as active executions; use it as an invalidation hint after persisting durable state, not as a replacement for reconnect recovery.
1910
+ Note: \`state.execution\` is always \`null\` in endpoints since the thread is at rest. In thread endpoints, \`runCode\` forwards functions in imports, globals, and execution arguments as callable proxies. Call \`run.terminate(reason)\` to stop the sandbox. A caller disconnect also stops the run. When \`report\` is supplied, the host receives reports during the run and \`run.reports\` updates as reports arrive. \`state.emit(event, data)\` broadcasts a custom WebSocket event from endpoints as well as active executions; use it as an invalidation hint after persisting durable state, not as a replacement for reconnect recovery.
1854
1911
 
1855
1912
  ## ThreadState Methods
1856
1913
 
1914
+ \`getMessages()\` returns messages newest first by default. Set \`order: 'asc'\` for oldest first.
1915
+ \`getMessage(id)\` finds persisted messages at any depth. It also finds pending messages from the message list. It returns \`null\` for unknown IDs.
1916
+ \`updateMessage(id, updates)\` updates a persisted message. It returns the updated \`Message\`.
1917
+ Updates to missing or pending messages fail before update hooks run.
1918
+ Message results include \`reasoning_content\`, \`reasoning_details\`, \`prompt\`, and available subagent fields: \`subagent_id\`, \`subagent_name\`, \`subagent_title\`, \`subagent_description\`, \`subagent_status\`, \`subagent_relationship\`, \`subagent_blocking\`, \`subagent_thread_name\`, and \`subagent_spawn_group_id\`.
1919
+
1857
1920
  Access thread data through the state object:
1858
1921
 
1859
1922
  \`\`\`typescript
@@ -1894,6 +1957,12 @@ export default defineThreadEndpoint(async (req, state) => {
1894
1957
  });
1895
1958
  \`\`\`
1896
1959
 
1960
+ \`state.loadModel\`, \`state.loadPrompt\`, and \`state.loadAgent\` enforce package
1961
+ visibility. Global code can load unpacked definitions and packed entry agents.
1962
+ Packed code can load its own definitions and other packages' entry agents.
1963
+ A packed model cannot fall back to a host model with the same short name.
1964
+ A refused load returns the same not-found error as a missing definition.
1965
+
1897
1966
  ## POST with Request Body
1898
1967
 
1899
1968
  \`\`\`typescript
@@ -1904,7 +1973,7 @@ export default defineThreadEndpoint(async (req, state) => {
1904
1973
  const body = await req.json();
1905
1974
  const { format = 'json' } = body;
1906
1975
 
1907
- const { messages } = await state.getMessages();
1976
+ const { messages } = await state.getMessages({ order: 'asc' });
1908
1977
 
1909
1978
  if (format === 'csv') {
1910
1979
  const csv = messages.map(m => \`\${m.role},\${m.content}\`).join('\\n');
@@ -2043,6 +2112,8 @@ the user event stream at \`/api/users/me/stream\`), \`listThreads()\`,
2043
2112
  \`fetch(grant, url, init)\` (privileged fetch through a credential grant), and
2044
2113
  \`thread(threadId)\` (raise one of the user's threads at rest).
2045
2114
 
2115
+ \`user.identity()\` returns a \`UserIdentity\`. Its \`username\` and \`role\` fields may be absent or null.
2116
+
2046
2117
  ## User Rooms
2047
2118
 
2048
2119
  A \`users/pkg/room.ts\` file may export \`defineUserRoom\` to handle hub frames
@@ -2136,7 +2207,7 @@ var APPROVED_DEPENDENCY_BUILD_SCRIPTS = [
2136
2207
  "sharp",
2137
2208
  "workerd"
2138
2209
  ];
2139
- var AGENTBUILDER_TEMPLATE_VERSION = "0.43.1";
2210
+ var AGENTBUILDER_TEMPLATE_VERSION = "0.44.1";
2140
2211
  var DEFAULT_TEMPLATE_VERSIONS = {
2141
2212
  standardAgents: `^${AGENTBUILDER_TEMPLATE_VERSION}`,
2142
2213
  sip: "^1.0.1",