@ziggs-ai/agent-sdk 0.48.8 → 0.48.10

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,12 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.48.10
6
+
7
+ - A task wake says which of its own proposals were answered. The inbox loop passes each input's `reason` to the task executor (`TaskInputRef.reason`), and the Claude prompt turns an approved or declined proposal made from the task into a work signal: give the hire its first task with `task_delegate` (`task_create` on the hire is refused from inside the task), or report a decline.
8
+
9
+ ## 0.48.9
10
+
5
11
  ## 0.48.8
6
12
 
7
13
  - Hosted agents get `task_pass_on`: an agent that opened a request and got no answer in time sends it up by making someone else the assignee, instead of cancelling it and asking again.
@@ -208,6 +208,44 @@ export function taskChaseLines(task, now = new Date()) {
208
208
  return lines;
209
209
  }
210
210
  /** Render ONE event's fields into prompt lines (shared by single and batch frames). */
211
+ const PROPOSAL_OUTCOMES = new Set(['proposal_approved', 'proposal_approved_execute', 'proposal_rejected']);
212
+ /** What the outcome of the agent's own proposal asks of it, in one line. */
213
+ function proposalOutcomeLine(reason, agreementId) {
214
+ const on = agreementId ? ` on agreement ${agreementId}` : '';
215
+ return reason === 'proposal_rejected'
216
+ ? `Work signal: your proposal${on} was declined. Tell the person you made it for, and ask what to change. Do not send the same proposal again.`
217
+ : `Work signal: your proposal${on} was approved, and you are working under it now. Do the next step you promised: ` +
218
+ 'if it is a hire for someone, create the first task under it (task_create) with their request. ' +
219
+ 'This wake does not carry the conversation that led to it; read that request (message_list) if you need it. ' +
220
+ 'Do not greet the provider or open a new conversation.';
221
+ }
222
+ /**
223
+ * What arrived for this task since its last wake. A proposal made inside the
224
+ * task reports its outcome here, on the task, where the work it is for can be
225
+ * read; it is the reason for the wake, so it is said in words.
226
+ */
227
+ function renderTaskInputLines(inputs, taskId, lines) {
228
+ if (!Array.isArray(inputs))
229
+ return;
230
+ for (const input of inputs) {
231
+ if (typeof input?.reason !== 'string' || !PROPOSAL_OUTCOMES.has(input.reason))
232
+ continue;
233
+ const agreementId = input.kind === 'agreement' && typeof input.id === 'string' ? input.id : undefined;
234
+ const on = agreementId ? ` on agreement ${agreementId}` : '';
235
+ if (input.reason === 'proposal_rejected') {
236
+ lines.push(proposalOutcomeLine(input.reason, agreementId));
237
+ continue;
238
+ }
239
+ // From inside the task, the hire is another party's work: task_create
240
+ // there is refused, and task_delegate is the door made for it.
241
+ lines.push(`Work signal: your proposal${on}, made from this task, was approved. ` +
242
+ `Give the hire its first task from this task with task_delegate (action "create", taskId ${taskId ?? 'this task'}` +
243
+ (agreementId ? `, agreementId ${agreementId}` : '') +
244
+ ', the hire\'s provider agent as assigneeId, and an instruction artifact you record). ' +
245
+ 'task_create on the hire is refused from here. If the delegation is refused because the people in the hire cannot read an input yet, ' +
246
+ 'ask for that consent with access_request as the refusal names, and delegate again once it is approved.');
247
+ }
248
+ }
211
249
  function renderEventLines(event, lines, now) {
212
250
  if (event?.type)
213
251
  lines.push(`Event type: ${event.type}`);
@@ -313,13 +351,7 @@ function renderEventLines(event, lines, now) {
313
351
  typeof resource.resourceId === 'string' &&
314
352
  resource.resourceId) ||
315
353
  '';
316
- const on = agreementId ? ` on agreement ${agreementId}` : '';
317
- lines.push(reason === 'proposal_rejected'
318
- ? `Work signal: your proposal${on} was declined. Tell the person you made it for, and ask what to change. Do not send the same proposal again.`
319
- : `Work signal: your proposal${on} was approved, and you are working under it now. Do the next step you promised: ` +
320
- 'if it is a hire for someone, create the first task under it (task_create) with their request. ' +
321
- 'This wake does not carry the conversation that led to it; read that request (message_list) if you need it. ' +
322
- 'Do not greet the provider or open a new conversation.');
354
+ lines.push(proposalOutcomeLine(reason, agreementId || undefined));
323
355
  // Prefer nested resource agreementId when the outer event omitted it.
324
356
  if (agreementId && !(typeof event.agreementId === 'string' && event.agreementId)) {
325
357
  lines.push(`Agreement: ${agreementId}`);
@@ -341,6 +373,7 @@ function renderEventLines(event, lines, now) {
341
373
  if (result && typeof result === 'object') {
342
374
  if (typeof result.taskId === 'string')
343
375
  lines.push(`Task: ${result.taskId}`);
376
+ renderTaskInputLines(result.inputs, typeof result.taskId === 'string' ? result.taskId : undefined, lines);
344
377
  if (typeof result.agreementId === 'string')
345
378
  lines.push(`Agreement: ${result.agreementId}`);
346
379
  if (typeof result.state === 'string')
@@ -517,7 +517,10 @@ export async function pollInboxOnce(deps, waitSeconds = 0, opts = {}) {
517
517
  const handled = await attempt(`task ${task.taskId}`, async () => {
518
518
  const executionContext = await prepareWorkExecution({ kind: 'task', id: task.taskId }, deps.creds.operatorKey, deps.ownAgentId, deps.baseUrl);
519
519
  const bucket = bucketOfRows(receipts);
520
- return withWorkExecution(executionContext, () => deps.onTask({ ...task, executionContext }, receipts.map(receipt => ({ kind: receipt.kind, id: receipt.resourceId, eventId: receipt.eventId ?? receipt.receiptId })), bucket ? { bucket } : undefined));
520
+ return withWorkExecution(executionContext, () => deps.onTask({ ...task, executionContext }, receipts.map(receipt => ({
521
+ kind: receipt.kind, id: receipt.resourceId, eventId: receipt.eventId ?? receipt.receiptId,
522
+ ...(typeof receipt.reason === 'string' && receipt.reason ? { reason: receipt.reason } : {}),
523
+ })), bucket ? { bucket } : undefined));
521
524
  });
522
525
  if (handled) {
523
526
  deps.seen.mark(key);
package/dist/types.d.ts CHANGED
@@ -24,6 +24,8 @@ export interface TaskInputRef {
24
24
  kind: import('@ziggs-ai/contracts').ResourceKind;
25
25
  id: string;
26
26
  eventId: string;
27
+ /** Why it arrived, when the server said (e.g. the outcome of a proposal made in the task). */
28
+ reason?: string;
27
29
  }
28
30
  export interface TaskRef {
29
31
  inputs?: TaskInputRef[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziggs-ai/agent-sdk",
3
- "version": "0.48.8",
3
+ "version": "0.48.10",
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.7",
34
- "@ziggs-ai/contracts": "0.50.1",
33
+ "@ziggs-ai/api-client": "0.42.8",
34
+ "@ziggs-ai/contracts": "0.50.2",
35
35
  "ajv": "^8.17.1",
36
36
  "dotenv": "^17.2.3",
37
37
  "openai": "^4.0.0",