@ziggs-ai/agent-sdk 0.48.22 → 0.48.24

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,14 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.48.24
6
+
7
+ ## 0.48.23
8
+
9
+ - Hosted agents get `page` with the default bucket tools, beside `page_guide`.
10
+ - `people` (discovery tools) finds teammates by name.
11
+ - `task_create` says who can be given a task without an agreement: your person, a teammate, or an agent your owner runs.
12
+
5
13
  ## 0.48.22
6
14
 
7
15
  - An agent's own `wake_at` that is refused because the work's audience or authority changed since it was set now runs once under a freshly prepared execution context. Before, every retry reused the ended context and was refused again.
package/dist/Agent.d.ts CHANGED
@@ -315,8 +315,9 @@ export declare class Agent {
315
315
  private runTimerEvent;
316
316
  /**
317
317
  * The lane's action, prepared again, when `err` says its saved context was
318
- * ended by a change of audience or authority. Undefined for any other
319
- * failure, for a lane with no exact action, and when the backend refuses.
318
+ * ended by a change of audience or authority. `'ended'` when the backend
319
+ * refuses it as no longer this agent's work (403 or 404). Undefined for any
320
+ * other failure, and for a lane with no exact action.
320
321
  */
321
322
  private freshContextAfterChange;
322
323
  private executionControlOn;
package/dist/Agent.js CHANGED
@@ -494,6 +494,14 @@ export class Agent {
494
494
  if (ev.type !== 'wake-at')
495
495
  return;
496
496
  const fresh = await this.freshContextAfterChange(err, laneKey);
497
+ if (fresh === 'ended') {
498
+ // The backend says the work is no longer this agent's to do (the task
499
+ // ended or was handed on). The wake can never run again, so it is not
500
+ // retried or kept for the next start.
501
+ runtimeLog.info('Agent', `wake-at laneKey=${laneKey} dropped: its work has ended`);
502
+ settle();
503
+ return;
504
+ }
497
505
  if (fresh) {
498
506
  try {
499
507
  await this.eventQueue.enqueue(ev, laneKey, fresh);
@@ -510,8 +518,9 @@ export class Agent {
510
518
  }
511
519
  /**
512
520
  * The lane's action, prepared again, when `err` says its saved context was
513
- * ended by a change of audience or authority. Undefined for any other
514
- * failure, for a lane with no exact action, and when the backend refuses.
521
+ * ended by a change of audience or authority. `'ended'` when the backend
522
+ * refuses it as no longer this agent's work (403 or 404). Undefined for any
523
+ * other failure, and for a lane with no exact action.
515
524
  */
516
525
  async freshContextAfterChange(err, laneKey) {
517
526
  if (err?.code !== 'EXECUTION_CONTEXT_CHANGED')
@@ -524,6 +533,10 @@ export class Agent {
524
533
  }
525
534
  catch (refused) {
526
535
  runtimeLog.warn('Agent', `wake-at laneKey=${laneKey} could not prepare a fresh execution context: ${refused?.message || refused}`);
536
+ // Refused or gone: no later attempt is authorized either.
537
+ const status = refused?.status;
538
+ if (status === 403 || status === 404)
539
+ return 'ended';
527
540
  return undefined;
528
541
  }
529
542
  }
@@ -85,10 +85,10 @@ export { listTasksTool, cancelTaskTool, delegateTaskTool, passTaskOnTool };
85
85
  * with the people it is for and sends inside it. A file reaches people the same
86
86
  * way, by being put in a bucket with them: `bucket_create` takes items, and
87
87
  * `bucket_insert` puts one in a bucket that exists. `page_guide` is how a
88
- * working page is built; read it before `bucket_send` with a page. Every hosted
88
+ * working page is built, and `page` posts it. Every hosted
89
89
  * agent has these, the same tool objects `BUCKET_TOOLS` hands out.
90
90
  */
91
- const BUCKET_DEFAULTS = BUCKET_TOOLS.filter((tool) => ['bucket_create', 'bucket_send', 'bucket_insert', 'page_guide'].includes(String(tool.schema.function.name)));
91
+ const BUCKET_DEFAULTS = BUCKET_TOOLS.filter((tool) => ['bucket_create', 'bucket_send', 'bucket_insert', 'page_guide', 'page'].includes(String(tool.schema.function.name)));
92
92
  export const CLAUDE_SDK_TOOLS = [
93
93
  contextSnapshotTool,
94
94
  messageSendTool,
@@ -1,9 +1,10 @@
1
1
  import type { RawEvent } from '../runtime/buildOutcome.js';
2
2
  export declare function agreementEventId(event: RawEvent | undefined): string | undefined;
3
3
  /**
4
- * Provider acceptance leaves a standing listing OPEN with its buyer slot still
5
- * a broadcast. It is not a customer hire. Check the full authoritative row;
6
- * /status, event actor ids and the word "approved" cannot prove this shape.
4
+ * Provider acceptance leaves a standing listing OPEN with its paying side still
5
+ * empty: nobody has taken it yet. It is not a customer hire. Check the full
6
+ * authoritative row; /status, event actor ids and the word "approved" cannot
7
+ * prove this shape.
7
8
  */
8
9
  export declare function isOwnUnclaimedStandingOffer(value: unknown, agreementId: string, agentId: string): boolean;
9
10
  /** Remove only proven listing-acceptance notices; mixed batches keep all real work. */
@@ -1,5 +1,4 @@
1
- import { SERVER_EVENTS } from '@ziggs-ai/contracts';
2
- import { isBroadcastTarget } from '@ziggs-ai/api-client';
1
+ import { SERVER_EVENTS, isSellerListing } from '@ziggs-ai/contracts';
3
2
  import { getBatchEvents } from '../context/batch.js';
4
3
  function record(value) {
5
4
  return value !== null && typeof value === 'object' && !Array.isArray(value)
@@ -21,21 +20,18 @@ export function agreementEventId(event) {
21
20
  return ids.length === 1 ? ids[0] : undefined;
22
21
  }
23
22
  /**
24
- * Provider acceptance leaves a standing listing OPEN with its buyer slot still
25
- * a broadcast. It is not a customer hire. Check the full authoritative row;
26
- * /status, event actor ids and the word "approved" cannot prove this shape.
23
+ * Provider acceptance leaves a standing listing OPEN with its paying side still
24
+ * empty: nobody has taken it yet. It is not a customer hire. Check the full
25
+ * authoritative row; /status, event actor ids and the word "approved" cannot
26
+ * prove this shape.
27
27
  */
28
28
  export function isOwnUnclaimedStandingOffer(value, agreementId, agentId) {
29
29
  const row = record(value);
30
- const parties = record(row?.parties);
31
- const payer = record(parties?.payer);
32
- const provider = record(parties?.provider);
30
+ const provider = record(record(row?.parties)?.provider);
33
31
  return row?.agreementId === agreementId &&
34
32
  row.status === 'open' &&
35
- row.providerPinned === true &&
36
33
  provider?.actor === agentId &&
37
- typeof payer?.principal === 'string' &&
38
- isBroadcastTarget(payer.principal);
34
+ isSellerListing(row);
39
35
  }
40
36
  /** Remove only proven listing-acceptance notices; mixed batches keep all real work. */
41
37
  export async function filterStandingOfferNotices(event, agentId, readAgreement) {
@@ -206,7 +206,7 @@ export async function executeToolWithSideEffects(deps, eff, effect, roster) {
206
206
  state: 'started',
207
207
  tool: effect.name,
208
208
  ...(argsPreview ? { args: argsPreview } : {}),
209
- }, effect.writeKeys?.artifactKey({ s: 'started', t: effect.name, a: argsPreview }), binding?.agreementId ?? effect.serviceAgreementId, binding?.taskId);
209
+ }, effect.writeKeys?.artifactKey({ s: 'started', t: effect.name, a: argsPreview }), (binding ? binding.agreementId ?? undefined : effect.serviceAgreementId), binding?.taskId);
210
210
  const lastUser = roster.users.find((u) => u.userId || u.id);
211
211
  // Accumulate token usage from any nested LLM call the tool makes (llmTool),
212
212
  // so it can be folded into the turn's authoritative token count.
@@ -240,7 +240,7 @@ export async function executeToolWithSideEffects(deps, eff, effect, roster) {
240
240
  senderId: effect.senderId ?? lastUser?.userId ?? lastUser?.id,
241
241
  senderType: effect.senderType ?? (lastUser ? 'USER' : undefined),
242
242
  onBehalfOfAgreementId: binding?.agreementId ?? effect.onBehalfOfAgreementId,
243
- serviceAgreementId: binding?.agreementId ?? effect.serviceAgreementId,
243
+ serviceAgreementId: (binding ? binding.agreementId ?? undefined : effect.serviceAgreementId),
244
244
  ...(binding ? { executionTaskId: binding.taskId, wakeAgreementId: binding.agreementId } : {}),
245
245
  memory: effect.memory,
246
246
  writeKeys: effect.writeKeys,
@@ -263,7 +263,7 @@ export async function executeToolWithSideEffects(deps, eff, effect, roster) {
263
263
  state: 'completed',
264
264
  tool: effect.name,
265
265
  result: clipped,
266
- }, effect.writeKeys?.artifactKey({ s: 'completed', t: effect.name, r: clipped }), binding?.agreementId ?? effect.serviceAgreementId, binding?.taskId);
266
+ }, effect.writeKeys?.artifactKey({ s: 'completed', t: effect.name, r: clipped }), (binding ? binding.agreementId ?? undefined : effect.serviceAgreementId), binding?.taskId);
267
267
  sendTelemetry(deps.telemetryClient, buildToolIngestPayload({
268
268
  sessionId: effect.sessionId,
269
269
  tool: effect.name,
@@ -281,7 +281,7 @@ export async function executeToolWithSideEffects(deps, eff, effect, roster) {
281
281
  state: 'failed',
282
282
  tool: effect.name,
283
283
  error: errMsg,
284
- }, effect.writeKeys?.artifactKey({ s: 'failed', t: effect.name, e: errMsg }), binding?.agreementId ?? effect.serviceAgreementId, binding?.taskId);
284
+ }, effect.writeKeys?.artifactKey({ s: 'failed', t: effect.name, e: errMsg }), (binding ? binding.agreementId ?? undefined : effect.serviceAgreementId), binding?.taskId);
285
285
  sendTelemetry(deps.telemetryClient, buildToolIngestPayload({
286
286
  sessionId: effect.sessionId,
287
287
  tool: effect.name,
@@ -133,7 +133,7 @@ export const taskUpdatePlanStepTool = defineTool('task_update_plan_step', {
133
133
  description: "Who this task now waits on, because you just asked them: { kind: 'user' | 'agent', id } — both fields required. Send it when you ask — with the step you are ticking, or on its own when the ask is all that happened. Your person then sees the task as waiting on them rather than as running, which is the difference between a job that looks stalled and one that is waiting for an answer. It clears itself: any later progress that does not restate it, and any terminal state, drops it.",
134
134
  },
135
135
  }, handlerFor('task_update_plan_step'), { description: "Update the status of a single step within a task's plan, and say who you are waiting on when you have just asked somebody. A task with no plan can still carry the waiting-on on its own." });
136
- export const taskCreateTool = defineTool('task_create', { agreementId: { type: 'string', description: 'Agreement the work is done under. Omit for a teammate or an agent your owner runs.' }, description: { type: 'string', required: true }, parentTaskId: 'string', assigneeId: { type: 'string', description: 'Explicitly hand this task to one specific agent (e.g. a worker your orchestrator selected via agent search) instead of leaving it unassigned. Must be a party on the agreement (payer, provider, creator, or creator agent).' }, inputArtifactIds: { type: 'array', items: { type: 'string' }, description: 'Prior-step output artifact handles, for structured input links.' }, plan: { type: 'object' }, planReviewTiming: planReviewTimingParam, requireMidWorkPlanAck: 'boolean', dueAt: dueAtParam, checkBack: checkBackParam, sources: SOURCES_PARAM }, handlerFor('task_create'), { description: 'Create a new task under an existing approved agreement. Use when the contract is already in place. Pass assigneeId to delegate the task to a specific agent rather than leaving it open. For work that means chasing an answer out of somebody, set dueAt and checkBack so the holder knows when to stop and how often it may remind.' });
136
+ export const taskCreateTool = defineTool('task_create', { agreementId: { type: 'string', description: 'Agreement the work is done under. Omit for a teammate or an agent your owner runs.' }, description: { type: 'string', required: true }, parentTaskId: 'string', assigneeId: { type: 'string', description: 'Who works it: your person, a teammate, an agent your owner runs, or under agreementId anyone it lets you give work. Required without agreementId.' }, inputArtifactIds: { type: 'array', items: { type: 'string' }, description: 'Prior-step output artifact handles, for structured input links.' }, plan: { type: 'object' }, planReviewTiming: planReviewTimingParam, requireMidWorkPlanAck: 'boolean', dueAt: dueAtParam, checkBack: checkBackParam, sources: SOURCES_PARAM }, handlerFor('task_create'), { description: 'Give someone a task: your person, a teammate, an agent your owner runs, or anyone an agreement lets you give work (name it as agreementId). For work that means chasing an answer out of somebody, set dueAt and checkBack so the holder knows when to stop and how often it may remind.' });
137
137
  export const PROTOCOL_TOOLS = [
138
138
  agreementProposeTool, agreementSubcontractTool,
139
139
  agreementRespondTool, agreementClaimTool, agreementCounterTool, agreementGetTool, agreementRevokeTool,
@@ -1,4 +1,5 @@
1
1
  import type { ToolDefinition } from '../../../tools/defineTool.js';
2
2
  export declare const agentSearchTool: ToolDefinition;
3
3
  export declare const agentGetTool: ToolDefinition;
4
+ export declare const peopleTool: ToolDefinition;
4
5
  export declare const DISCOVERY_TOOLS: ToolDefinition[];
@@ -1,8 +1,9 @@
1
- import { agentSearchCapability, agentGetCapability } from '@ziggs-ai/api-client';
1
+ import { agentSearchCapability, agentGetCapability, peopleCapability } from '@ziggs-ai/api-client';
2
2
  import { toolFromCapability } from '../../../tools/capabilityAdapter.js';
3
3
  // agent discovery is a shared capability definition (api-client),
4
4
  // so search shaping (zero-hit hint, reachability rows) is identical
5
5
  // on both surfaces.
6
6
  export const agentSearchTool = toolFromCapability(agentSearchCapability);
7
7
  export const agentGetTool = toolFromCapability(agentGetCapability);
8
- export const DISCOVERY_TOOLS = [agentSearchTool, agentGetTool];
8
+ export const peopleTool = toolFromCapability(peopleCapability);
9
+ export const DISCOVERY_TOOLS = [agentSearchTool, agentGetTool, peopleTool];
@@ -3,7 +3,7 @@ import type { Task } from '@ziggs-ai/api-client';
3
3
  import type { ToolDefinition } from '../tools/defineTool.js';
4
4
  type Row = Record<string, unknown>;
5
5
  export interface ExecutionBinding {
6
- agreementId: string;
6
+ agreementId: string | null;
7
7
  taskId: string;
8
8
  }
9
9
  interface ControllerOptions {
@@ -97,7 +97,9 @@ export class ExecutionController {
97
97
  const binding = await this.verify(taskId, TASK_MANAGEMENT.has(name));
98
98
  for (const key of AUTHORITY_ARGS) {
99
99
  if (args[key] != null && args[key] !== binding.agreementId) {
100
- this.refuse('AGREEMENT_SCOPE_MISMATCH', `${key} must be the task's own agreement (${binding.agreementId}).`);
100
+ this.refuse('AGREEMENT_SCOPE_MISMATCH', binding.agreementId
101
+ ? `${key} must be the task's own agreement (${binding.agreementId}).`
102
+ : `${key} must be left out: the task has no agreement, so it lends no agreement's authority.`);
101
103
  }
102
104
  }
103
105
  const handlerArgs = { ...args };
@@ -116,11 +118,16 @@ export class ExecutionController {
116
118
  if (task.taskId !== taskId || (task.executorIsYou !== true && task.assigneeId !== this.options.agentId)) {
117
119
  this.refuse('TASK_NOT_HELD', `Task ${taskId} is not assigned to you. Work only under a task you hold.`);
118
120
  }
119
- const agreementId = id(task.agreementId);
120
- const agreement = agreementId ? row(await this.options.readAgreement(agreementId)) : {};
121
- if (!agreementId || agreement.agreementId !== agreementId || agreement.status !== 'active'
122
- || agreement.engagementKind === 'link' || isListing(agreement)) {
123
- this.refuse('AGREEMENT_INACTIVE', 'The task\'s agreement is not an active work agreement. Conversation links and listings do not authorize work.');
121
+ // A task given with no agreement (by the person who runs you, or a
122
+ // teammate) is work of its own: no agreement above it to check. A task
123
+ // that names one works only while that agreement is active work.
124
+ const agreementId = id(task.agreementId) ?? null;
125
+ if (agreementId) {
126
+ const agreement = row(await this.options.readAgreement(agreementId));
127
+ if (agreement.agreementId !== agreementId || agreement.status !== 'active'
128
+ || agreement.engagementKind === 'link' || isListing(agreement)) {
129
+ this.refuse('AGREEMENT_INACTIVE', 'The task\'s agreement is not an active work agreement. Conversation links and listings do not authorize work.');
130
+ }
124
131
  }
125
132
  const state = String(task.state);
126
133
  if (CLOSED.has(state) || task.control?.action === 'stop') {
package/dist/types.d.ts CHANGED
@@ -404,7 +404,7 @@ export interface ToolCallResult {
404
404
  errorCode?: string;
405
405
  /** Host-verified work binding, supplied by the execution controller. */
406
406
  execution?: {
407
- agreementId: string;
407
+ agreementId: string | null;
408
408
  taskId: string;
409
409
  };
410
410
  result?: unknown;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziggs-ai/agent-sdk",
3
- "version": "0.48.22",
3
+ "version": "0.48.24",
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,8 +30,8 @@
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.42.18",
34
- "@ziggs-ai/contracts": "0.52.0",
33
+ "@ziggs-ai/api-client": "0.42.23",
34
+ "@ziggs-ai/contracts": "0.55.0",
35
35
  "ajv": "^8.17.1",
36
36
  "dotenv": "^17.2.3",
37
37
  "openai": "^4.0.0",