@ziggs-ai/agent-sdk 0.48.16 → 0.48.17

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,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.48.17
6
+
5
7
  ## 0.48.16
6
8
 
7
9
  ## 0.48.15
@@ -2,6 +2,14 @@ import type { TaskUpdateState } from '@ziggs-ai/contracts';
2
2
  import type { WriteSource } from '@ziggs-ai/api-client';
3
3
  import { type HeldTaskCreate, type Task } from '@ziggs-ai/api-client';
4
4
  import type { CountTasksFilters, CreateTaskData, TaskChargeStatement } from '@ziggs-ai/api-client';
5
+ /**
6
+ * What goes back to the delegator as one output: the summary, the result's
7
+ * other fields, and the bodies of the outputs the task made. An agent that
8
+ * puts its drafts in the result (`{ summary, rows: [...] }`) and records no
9
+ * output of its own used to return the summary line alone, and the delegator
10
+ * had nothing to review.
11
+ */
12
+ export declare function delegatedResultText(result: unknown, bodies: readonly string[]): string;
5
13
  export declare class TaskService {
6
14
  private creds;
7
15
  constructor(operatorKey: string, agentId: string);
@@ -1,5 +1,30 @@
1
1
  import { createTask, getTask, getActiveTasksForAgent, getSubtasks, updateTaskState, updateTaskPlanStep, updateTaskPlanSteps, cancelTask, reportTask, setTaskSatisfaction, countTasks, acknowledgeTaskControl, presentTaskOutcome, returnTaskResult, ArtifactsClient, withWorkExecution, ARTIFACT_INLINE_TEXT_MAX_CHARS, } from '@ziggs-ai/api-client';
2
2
  import { runtimeLog } from '../../shared/runtimeLog.js';
3
+ /**
4
+ * What goes back to the delegator as one output: the summary, the result's
5
+ * other fields, and the bodies of the outputs the task made. An agent that
6
+ * puts its drafts in the result (`{ summary, rows: [...] }`) and records no
7
+ * output of its own used to return the summary line alone, and the delegator
8
+ * had nothing to review.
9
+ */
10
+ export function delegatedResultText(result, bodies) {
11
+ const summary = result?.summary;
12
+ const head = typeof summary === 'string' ? summary : safeJsonStringify(result);
13
+ const rest = typeof summary === 'string' && result && typeof result === 'object' && !Array.isArray(result)
14
+ ? Object.fromEntries(Object.entries(result)
15
+ .filter(([key, value]) => key !== 'summary' && value !== undefined && value !== null && value !== ''))
16
+ : {};
17
+ let fields;
18
+ if (Object.keys(rest).length) {
19
+ try {
20
+ fields = `## Result\n\n${JSON.stringify(rest, null, 2)}`;
21
+ }
22
+ catch {
23
+ fields = `## Result\n\n${String(safeJsonStringify(rest))}`;
24
+ }
25
+ }
26
+ return [head, fields, ...bodies].filter((part) => !!part && !!String(part).trim()).join('\n\n');
27
+ }
3
28
  function safeJsonStringify(value) {
4
29
  if (value === null || value === undefined)
5
30
  return value;
@@ -99,14 +124,12 @@ export class TaskService {
99
124
  const task = await getTask(taskId, this.creds);
100
125
  if (!task?.delegation || task.delegation.returnedArtifactId)
101
126
  return undefined;
102
- const summary = result?.summary;
103
- const head = typeof summary === 'string' ? summary : safeJsonStringify(result);
104
127
  const artifacts = new ArtifactsClient(this.creds.operatorKey, this.creds.agentId);
105
128
  // Only one output goes back to the delegator, so it carries the bodies of
106
129
  // the other outputs this task made: the pages or drafts themselves, not
107
130
  // only the line that names them.
108
131
  const bodies = await this.outputBodies(artifacts, taskId);
109
- const text = [head, ...bodies].filter((part) => !!part && !!String(part).trim()).join('\n\n');
132
+ const text = delegatedResultText(result, bodies);
110
133
  if (!text.trim())
111
134
  return undefined;
112
135
  const recorded = await artifacts.writeStrict({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziggs-ai/agent-sdk",
3
- "version": "0.48.16",
3
+ "version": "0.48.17",
4
4
  "description": "Agent framework SDK for building autonomous agents on the Ziggs platform",
5
5
  "homepage": "https://ziggsai.com/docs",
6
6
  "bugs": {