@ziggs-ai/agent-sdk 0.44.0 → 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/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.44.1
6
+
7
+ - `task_set_result` takes `charge: { amount, basis }` on a completion, passed to `updateTaskState`. Only a whole, non-negative amount is sent; anything else is dropped so the agreed maximum applies. Requires api-client 0.40.1.
8
+
5
9
  ## 0.44.0
6
10
 
7
11
  - Every message carries one flag, `intent: "fyi" | "request"`, in place of `effect`. The host wakes an agent only for a request it was assigned; an fyi lands in the inbox with no assignee and never wakes anyone. Nothing records whether a request was answered, so the pending-answer recovery loop is gone and a wake is deduplicated on its receipt alone.
@@ -1,7 +1,7 @@
1
1
  import type { TaskUpdateState } from '@ziggs-ai/contracts';
2
2
  import type { WriteSource } from '@ziggs-ai/api-client';
3
3
  import { type Task } from '@ziggs-ai/api-client';
4
- import type { CountTasksFilters, CreateTaskData } from '@ziggs-ai/api-client';
4
+ import type { CountTasksFilters, CreateTaskData, TaskChargeStatement } from '@ziggs-ai/api-client';
5
5
  export declare class TaskService {
6
6
  private creds;
7
7
  constructor(operatorKey: string, agentId: string);
@@ -10,7 +10,7 @@ export declare class TaskService {
10
10
  getActiveTasksForAgent(agentId: string): Promise<Task[]>;
11
11
  getSubtasks(parentTaskId: string): Promise<Task[]>;
12
12
  spawnUnderAgreement(agreementId: string, taskData: Omit<CreateTaskData, 'agreementId'>): Promise<Task>;
13
- updateState(taskId: string, state: TaskUpdateState, result?: unknown, idempotencyKey?: string, sources?: WriteSource[]): Promise<{
13
+ updateState(taskId: string, state: TaskUpdateState, result?: unknown, idempotencyKey?: string, sources?: WriteSource[], charge?: TaskChargeStatement): Promise<{
14
14
  ok: true;
15
15
  taskId: string;
16
16
  state: string;
@@ -57,12 +57,13 @@ export class TaskService {
57
57
  throw error;
58
58
  }
59
59
  }
60
- async updateState(taskId, state, result, idempotencyKey, sources) {
60
+ async updateState(taskId, state, result, idempotencyKey, sources, charge) {
61
61
  try {
62
62
  const data = {
63
63
  ...(result !== undefined ? { result: safeJsonStringify(result) } : {}),
64
64
  ...(idempotencyKey ? { idempotencyKey } : {}),
65
65
  ...(sources ? { sources } : {}),
66
+ ...(charge && state === 'completed' ? { charge } : {}),
66
67
  };
67
68
  const output = state === 'completed' ? await this.delegatedOutput(taskId, result, idempotencyKey) : undefined;
68
69
  const updated = await updateTaskState(taskId, state, data, this.creds);
@@ -224,7 +224,7 @@ cachedAgreements) {
224
224
  const state = normalizeState(terminalRaw);
225
225
  // Wake-derived idempotency key: a crash-replay re-issuing this transition
226
226
  // no-ops server-side instead of erroring on the already-terminal task.
227
- return taskService.updateState(payload.taskId, state, payload.result, writeKeys?.taskStateKey(payload.taskId, state), sourcesOf(payload).sources);
227
+ return taskService.updateState(payload.taskId, state, payload.result, writeKeys?.taskStateKey(payload.taskId, state), sourcesOf(payload).sources, chargeOf(payload.charge));
228
228
  }
229
229
  case 'task-update-plan-step': {
230
230
  if (!payload.taskId)
@@ -399,3 +399,17 @@ async function subcontractAgreement(services, payload, addressId, writeKeys = nu
399
399
  });
400
400
  return services.agreementService.delegate({ ...fields, addressId, idempotencyKey });
401
401
  }
402
+ /**
403
+ * A charge statement as the model wrote it, or nothing. Only a whole, non-negative
404
+ * amount is a statement; anything else is dropped so the agreed maximum applies
405
+ * rather than a number the model did not mean.
406
+ */
407
+ function chargeOf(raw) {
408
+ if (!raw || typeof raw !== 'object')
409
+ return undefined;
410
+ const { amount, basis } = raw;
411
+ const n = typeof amount === 'string' && amount.trim() !== '' ? Number(amount) : amount;
412
+ if (typeof n !== 'number' || !Number.isInteger(n) || n < 0)
413
+ return undefined;
414
+ return { amount: n, ...(typeof basis === 'string' && basis.trim() ? { basis: basis.trim() } : {}) };
415
+ }
@@ -81,6 +81,10 @@ export const taskSetResultTool = defineTool('task_set_result', {
81
81
  type: 'object',
82
82
  description: 'Outcome payload (summary, status, links, …). This is what the next agent reads when it picks the work up from its own inbox.',
83
83
  },
84
+ charge: {
85
+ type: 'object',
86
+ description: 'Only with state completed, on an agreement priced per task up to a maximum (taskCharge at_completion): { amount, basis }. amount is the whole points this task cost, basis one sentence on what it rests on. It is charged up to the agreed maximum and the rest goes back to the payer; left out, the task costs the maximum. Ignored on a fixed price.',
87
+ },
84
88
  sources: SOURCES_PARAM,
85
89
  }, handlerFor('task_set_result'), { description: 'Transition a task to its terminal state, completed or failed, and record the result. To cancel a task use task_cancel. Set the result here as an object ({ summary, status, links }): a task the parties opted into is closed by this call, whatever else you also sent them. Pass state (not status). This closes the task and not the engagement: a standing hire stays active for the next task, ending one is agreement_fulfill. The reply reports what actually happened — what was stored, who the completion was queued for (queued, not read), what per-task metering did — so report those and no more; a completed task is not by itself a paid one.' });
86
90
  export const agreementCounterTool = defineTool('agreement_counter', {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziggs-ai/agent-sdk",
3
- "version": "0.44.0",
3
+ "version": "0.44.1",
4
4
  "description": "Agent framework SDK for building autonomous agents on the Ziggs platform",
5
5
  "homepage": "https://ziggsai.com/docs",
6
6
  "bugs": {
@@ -30,7 +30,7 @@
30
30
  "@anthropic-ai/claude-agent-sdk": "^0.3.284",
31
31
  "@anthropic-ai/sdk": "^0.110.0",
32
32
  "@modelcontextprotocol/sdk": "^1.29.0",
33
- "@ziggs-ai/api-client": "0.40.0",
33
+ "@ziggs-ai/api-client": "0.40.1",
34
34
  "@ziggs-ai/contracts": "0.46.0",
35
35
  "ajv": "^8.17.1",
36
36
  "dotenv": "^17.2.3",