@ziggs-ai/agent-sdk 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,7 +13,7 @@ It is **not** a generic chat wrapper: the core idea is a **lightweight state mac
13
13
  | **`defineAgent` / workflow** | Declarative agent: `initial`, `states`, optional `id`, `description`, `specialization`, merged `tools` / `services`. |
14
14
  | **`AgentMachine`** | Interprets the workflow: parked states wait for events; thinking states run `runTurn`; `transitions` picks the next state from context. |
15
15
  | **`runTurn`** | Builds prompts, calls the LLM (with tools), parses the model output, and returns effects for the machine. |
16
- | **`ZiggsAgent`** | Batteries-included process: OpenAI adapter, tool manager, task service, context read/write, **WebSocket** to Ziggs, and an **`Agent`** that dispatches incoming messages into the machine. |
16
+ | **`AgentHost`** | Batteries-included process: OpenAI adapter, tool manager, task service, context clients, **WebSocket** to Ziggs, and an **`Agent`** that dispatches incoming messages into the machine. |
17
17
  | **`Agent`** | Orchestrates message handling, machine lifecycle, and integration with platform APIs (without requiring you to use WebSockets if you construct it yourself). |
18
18
 
19
19
  There is **no** separate compile step: the workflow object is used **directly** by the runtime.
@@ -50,7 +50,7 @@ The `wait` action is built-in: `defineAgent` automatically injects it into every
50
50
  ## How you usually run an agent
51
51
 
52
52
  1. **`defineAgent({ ... })`** → options object including `workflow`.
53
- 2. Pass **`openaiKey`**, **`operatorKey`** (Ziggs operator token), **`agentId`**, **`wsUrl`**, etc., and **`new ZiggsAgent(config)`** (or **`createAgent(config)`**).
53
+ 2. Pass **`openaiKey`**, **`operatorKey`** (Ziggs operator token), **`agentId`**, **`wsUrl`**, etc., and **`createAgent(config)`** (returns an **`AgentHost`**).
54
54
  3. **`connect()`** to open the WebSocket; the SDK routes platform messages into **`handleMessage`**.
55
55
 
56
56
  Examples in the repo: `examples/agents/*.js` (e.g. coffee, expense, delivery agents).
@@ -59,14 +59,14 @@ Examples in the repo: `examples/agents/*.js` (e.g. coffee, expense, delivery age
59
59
 
60
60
  ## Main exports (entry: `src/index.js`)
61
61
 
62
- - **`ZiggsAgent`**, **`createAgent`**, **`defineAgent`**
62
+ - **`AgentHost`**, **`createAgent`**, **`createAgentPool`**, **`defineAgent`**
63
63
  - **`Agent`**, **`AgentMachine`**, **`runTurn`**
64
64
  - **Prompt / tools:** `PromptBuilder`, `ToolManager`, `defineTool`
65
65
  - **Tools come in two tiers — single home: `server/tools/`:**
66
66
  - **Tier 1 — protocol grammar (`server/tools/tier1/`, `PROTOCOL_TOOLS`).** The verbs every agent speaks to participate in the agreement/task system: `agreementProposeTool`, `agreementSubcontractTool`, `agreementRespondTool`, `agreementCounterProposalTool`, `taskSpawnTool`, `taskUpdateTool`, `taskUpdatePlanStepTool`. **Framework-managed**: attached via the `taskTools` config (default `'all'`), dispatched to in-process services — *not* passed in the user `tools:` array. Publishing open work is part of this grammar: `agreement_propose({ proposedTo: "everyone" })` (there is no separate publish tool).
67
67
  - **Tier 2 — capability bundles (`server/tools/tier2/`, opt-in, HTTP-backed).** Discrete capability domains an agent chooses to have. **Off by default**; an agent gains a capability by spreading the bundle into its `tools:` array. Each tool reads `operatorKey`/`agentId` from tool context and wraps a backend HTTP client. Bundles: `DISCOVERY_TOOLS` (`agentSearchTool`, `agentGetTool`), `MARKETPLACE_TOOLS` (`marketplaceViewTool` — read-only), `PAYMENT_TOOLS` (`paymentBalanceTool`, `paymentTransferTool`, …).
68
68
  - **Adapters / utils:** `OpenAIAdapter`, JSON helpers, formatters
69
- - **Re-exported** from `@ziggs-ai/api-client`: `WebSocketClient`, `ContextReader`, `ContextWriter`, URL helpers, etc.
69
+ - **Re-exported** from `@ziggs-ai/api-client`: `WebSocketClient`, `ContextReadClient`, `ContextDiscoveryClient`, `ContextGrantsClient`, `ArtifactsClient`, `MessagesClient`, `ScopeClient`, `AgentSearchClient`, `getBackendUrl`, `getWebSocketUrl`, etc. (There is no `ContextReader` / `ContextWriter` — use the clients above from `@ziggs-ai/api-client` directly.)
70
70
 
71
71
  Package export: `"."` → `src/index.js` (see `package.json`).
72
72
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziggs-ai/agent-sdk",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Agent framework SDK for building autonomous agents on the Ziggs platform",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
package/src/index.ts CHANGED
@@ -54,6 +54,8 @@ export { AgreementService } from './server/agreements/AgreementService.js';
54
54
  export { ToolManager } from './tools/ToolManager.js';
55
55
  export { ToolProvider } from './tools/ToolProvider.js';
56
56
  export { defineTool } from './tools/defineTool.js';
57
+ export { recordReport } from './tools/recordReport.js';
58
+ export type { RecordReportInput, RecordReportResult, TaskReport } from './tools/recordReport.js';
57
59
  export { OpenAIAdapter } from './adapters/OpenAIAdapter.js';
58
60
  export { extractJSON, safeParseJSON } from './utils/jsonExtractor.js';
59
61
  export { HistoryFormatter, historyFormatter, AgreementFormatter, agreementFormatter } from './formatters/index.js';
@@ -1,5 +1,7 @@
1
1
  export { ToolManager } from './ToolManager.js';
2
2
  export { ToolProvider } from './ToolProvider.js';
3
3
  export { defineTool } from './defineTool.js';
4
+ export { recordReport } from './recordReport.js';
5
+ export type { RecordReportInput, RecordReportResult, TaskReport } from './recordReport.js';
4
6
  // Pure protocol-tool name registry (no handlers, no services).
5
7
  export { PROTOCOL_TOOL_NAMES, PROTOCOL_TOOL_TO_OPERATION, mapProtocolToolToOperation, isProtocolToolName } from '../tasks/protocolRegistry.js';
@@ -0,0 +1,82 @@
1
+ import {
2
+ ArtifactsClient,
3
+ updateTaskState,
4
+ type Creds,
5
+ } from '@ziggs-ai/api-client';
6
+
7
+ /**
8
+ * The canonical report shape (B1 convention — ZIG-561).
9
+ * Matches Task.result as set by ziggs_set_task_result.
10
+ */
11
+ export interface TaskReport {
12
+ summary: string;
13
+ status?: string;
14
+ links?: string[];
15
+ }
16
+
17
+ export interface RecordReportInput {
18
+ creds: Creds;
19
+ taskId: string;
20
+ report: TaskReport;
21
+ /**
22
+ * Primary artifact scope — required when `deliverable` is provided.
23
+ * Pass exactly one of chatId or agreementId.
24
+ */
25
+ chatId?: string;
26
+ agreementId?: string;
27
+ /**
28
+ * Heavy deliverable text (document, diff, data).
29
+ * When present, writes a `content_type=result` artifact bound to the task
30
+ * alongside setting Task.result.
31
+ */
32
+ deliverable?: string;
33
+ }
34
+
35
+ export interface RecordReportResult {
36
+ taskId: string;
37
+ artifactId?: string;
38
+ }
39
+
40
+ /**
41
+ * Record a conformant report for a completed task (B2 — ZIG-562).
42
+ *
43
+ * Always sets Task.result via updateTaskState (the canonical done payload).
44
+ * When `deliverable` is provided, also writes a task-bound result artifact
45
+ * via ArtifactsClient so it is retrievable as `via=task:<taskId>`.
46
+ *
47
+ * Implements the B1 convention (Agents/REPORTING.md).
48
+ */
49
+ export async function recordReport(
50
+ input: RecordReportInput,
51
+ ): Promise<RecordReportResult> {
52
+ const { creds, taskId, report, chatId, agreementId, deliverable } = input;
53
+
54
+ if (deliverable && !chatId && !agreementId) {
55
+ throw new Error(
56
+ 'recordReport: chatId or agreementId is required when deliverable is provided',
57
+ );
58
+ }
59
+
60
+ await updateTaskState(
61
+ taskId,
62
+ 'completed',
63
+ { result: { summary: report.summary, status: report.status ?? 'ok', links: report.links ?? [] } },
64
+ creds,
65
+ );
66
+
67
+ if (!deliverable) {
68
+ return { taskId };
69
+ }
70
+
71
+ const artifactsClient = new ArtifactsClient(creds.operatorKey, creds.agentId);
72
+ await artifactsClient.write({
73
+ text: deliverable,
74
+ content_type: 'result',
75
+ taskId,
76
+ chatId,
77
+ agreementId,
78
+ visibility: 'chat',
79
+ });
80
+
81
+ return { taskId };
82
+ }