@ziggs-ai/agent-sdk 0.38.1 → 0.38.2

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/dist/Agent.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { SERVER_EVENTS } from '@ziggs-ai/contracts';
1
2
  import { withAgreementContext } from './runtime/agreementContext.js';
2
3
  import { agreementLaneId, agreementIdFromLane, isContextAccessRequest } from '@ziggs-ai/api-client';
3
4
  import { createDeclaredPollRunner } from './platform/polls/declaredPollRunner.js';
@@ -556,7 +557,7 @@ export class Agent {
556
557
  : undefined);
557
558
  const actorId = typeof event.actorId === 'string' && event.actorId ? event.actorId : undefined;
558
559
  return this.eventQueue.enqueue({
559
- type: 'resource_changed',
560
+ type: SERVER_EVENTS.resourceChanged,
560
561
  resource: event,
561
562
  chatId: event.chatId,
562
563
  taskId: event.taskId,
@@ -1,16 +1,3 @@
1
- /**
2
- * Shared Claude-Agent-SDK cognition pieces.
3
- *
4
- * Everything a Claude-brain agent needs to turn a Ziggs wake into a `query()`
5
- * call, EXCEPT the loop itself. `ClaudeBrain` owns the loop (drive `query()`,
6
- * collect metrics); this module owns the periphery so it lives in one place and
7
- * is unit-testable without spinning up the SDK.
8
- *
9
- * The lockdown option set (`tools: []`, `strictMcpConfig`, `settingSources: []`,
10
- * bypass permissions, no local settings) is a security boundary, not a default —
11
- * it MUST be applied on every Claude-brain wake. Centralizing it here means a
12
- * caller cannot silently drift from it.
13
- */
14
1
  import { type Options, type SDKAssistantMessage } from '@anthropic-ai/claude-agent-sdk';
15
2
  import type { RawEvent } from '../runtime/buildOutcome.js';
16
3
  export interface ClaudeQueryOptionsParams {
@@ -11,6 +11,7 @@
11
11
  * it MUST be applied on every Claude-brain wake. Centralizing it here means a
12
12
  * caller cannot silently drift from it.
13
13
  */
14
+ import { SERVER_EVENTS } from '@ziggs-ai/contracts';
14
15
  import { SYSTEM_PROMPT_DYNAMIC_BOUNDARY, } from '@anthropic-ai/claude-agent-sdk';
15
16
  import { decisionWords } from '@ziggs-ai/api-client';
16
17
  import { getBatchEvents } from '../context/batch.js';
@@ -215,7 +216,7 @@ function renderEventLines(event, lines, now) {
215
216
  // store claim wakes as resource_changed (no chat, reason
216
217
  // proposal_approved). Distinct from the lifecycle hire path above: open the
217
218
  // buyer chat first, then greet and serve terms.
218
- if (event?.type === 'resource_changed') {
219
+ if (event?.type === SERVER_EVENTS.resourceChanged) {
219
220
  const resource = (event.resource ?? event);
220
221
  const reason = (typeof resource.reason === 'string' && resource.reason) ||
221
222
  (typeof event.reason === 'string' && event.reason) ||
@@ -7,6 +7,7 @@
7
7
  * manifest opts in. A hire a person formed (store claim) still wakes
8
8
  * so the provider can open the room and greet.
9
9
  */
10
+ import { SERVER_EVENTS } from '@ziggs-ai/contracts';
10
11
  const ACTIVATION_LIFECYCLE_OPS = new Set([
11
12
  'proposal_approved',
12
13
  'proposal_approved_execute',
@@ -62,7 +63,7 @@ export function isHireActivationNotice(event) {
62
63
  if (type === 'agreement_lifecycle' && operation && ACTIVATION_LIFECYCLE_OPS.has(operation)) {
63
64
  return true;
64
65
  }
65
- if (type !== 'resource_changed')
66
+ if (type !== SERVER_EVENTS.resourceChanged)
66
67
  return false;
67
68
  const resource = asRecord(ev.resource) ?? ev;
68
69
  const reason = typeof resource.reason === 'string' ? resource.reason : undefined;
@@ -1,3 +1,4 @@
1
+ import { SERVER_EVENTS } from '@ziggs-ai/contracts';
1
2
  import { isAgreementId, isBroadcastTarget } from '@ziggs-ai/api-client';
2
3
  import { getBatchEvents } from '../context/batch.js';
3
4
  function record(value) {
@@ -46,7 +47,7 @@ export async function filterStandingOfferNotices(event, agentId, readAgreement)
46
47
  const resource = record(item?.resource);
47
48
  const reason = resource?.reason ?? item?.reason;
48
49
  const id = agreementEventId(item);
49
- if (item?.type === 'resource_changed' && resource?.kind === 'agreement' &&
50
+ if (item?.type === SERVER_EVENTS.resourceChanged && resource?.kind === 'agreement' &&
50
51
  (reason === 'approval:approved' || reason === 'proposal_approved') && id) {
51
52
  // Inconclusive reads preserve the wake. An unavailable read must not eat
52
53
  // a legitimate customer hire or the answer to an agent's own request.
@@ -314,9 +314,6 @@ export async function pollInboxOnce(deps, waitSeconds = 0, opts = {}) {
314
314
  handledSoFar.add(request.agreementId);
315
315
  }
316
316
  }
317
- if (envelope.truncatedRequests) {
318
- warn(label, `inbox truncatedRequests=${envelope.truncatedRequests} (more requests than one pass surfaces — the tail follows on the next pass)`);
319
- }
320
317
  // Pending decisions are standing state, not deliveries: they keep appearing
321
318
  // until answered, so dedup them the same way tasks are deduped.
322
319
  for (const proposal of envelope.proposalsAwaitingMe) {
@@ -1,3 +1,4 @@
1
+ import { AGREEMENT_TERMINAL_STATES } from '@ziggs-ai/contracts';
1
2
  import { isBroadcastTarget, partyActorIds, presentClaimResult, } from '@ziggs-ai/api-client';
2
3
  // the link-summary rule lives in AgreementClient, at the point the
3
4
  // document is parsed. Every verb here inherits it through the client instead of
@@ -300,7 +301,7 @@ async function proposeAgreement(services, payload, chatId, writeKeys = null) {
300
301
  // party — instead of under that worker's sub-agreement, which the backend
301
302
  // rejects with 400 "assignee is not a party". Both are made deterministic here
302
303
  // using the chat's existing agreements.
303
- const TERMINAL_STATUS = new Set(['fulfilled', 'cancelled', 'refunded', 'rejected']);
304
+ const TERMINAL_STATUS = new Set(AGREEMENT_TERMINAL_STATES);
304
305
  async function agreementsInChat(services, chatId, cachedAgreements) {
305
306
  if (!chatId)
306
307
  return [];
@@ -1,3 +1,4 @@
1
+ import { SERVER_EVENTS } from '@ziggs-ai/contracts';
1
2
  import { isProtocolToolName, mapProtocolToolToOperation } from '../tasks/protocolRegistry.js';
2
3
  import { getBatchEvents, isTaskResultRelevantToAgent } from '../context/batch.js';
3
4
  import { bookForDelegation, ensureTaskBook, findBookHoldingPending, removeTaskBook, } from './taskBookkeeping.js';
@@ -108,7 +109,7 @@ function singleEventToOutcome(ev, ownAgentId) {
108
109
  }
109
110
  return { kind: 'subtask-finished', status: 'completed', task, result };
110
111
  }
111
- if (ev.type === 'resource_changed') {
112
+ if (ev.type === SERVER_EVENTS.resourceChanged) {
112
113
  const resource = (ev.resource ?? ev);
113
114
  const reason = resource.reason;
114
115
  if (resource.kind === 'agreement' &&
@@ -1,3 +1,6 @@
1
+ import { ContentTypes, type ContentType } from '@ziggs-ai/api-client';
2
+ export { ContentTypes, type ContentType };
3
+ /** Entry kinds. `task_history` is a legacy alias the wire still accepts. */
1
4
  export declare const EntryTypes: {
2
5
  readonly MESSAGE: "message";
3
6
  readonly NOTIFICATION: "notification";
@@ -5,15 +8,6 @@ export declare const EntryTypes: {
5
8
  readonly TASK_HISTORY: "task_history";
6
9
  };
7
10
  export type EntryType = (typeof EntryTypes)[keyof typeof EntryTypes];
8
- export declare const ContentTypes: {
9
- readonly TEXT: "text";
10
- readonly OPERATION: "operation";
11
- readonly CONTEXT: "context";
12
- readonly RESULT: "result";
13
- readonly TASK_UPDATE: "task_update";
14
- readonly THOUGHT: "thought";
15
- };
16
- export type ContentType = (typeof ContentTypes)[keyof typeof ContentTypes];
17
11
  export declare const ContextProperties: {
18
12
  readonly HISTORY: "history";
19
13
  readonly AGREEMENTS: "agreements";
@@ -1,20 +1,12 @@
1
- // Inlined from `@ziggs-ai/api-client` so the pure SDK doesn't depend on the
2
- // Ziggs HTTP client. Both client and server agree on these string constants
3
- // because the protocol is the same — they're just two views of one schema.
1
+ import { ContentTypes } from '@ziggs-ai/api-client';
2
+ export { ContentTypes };
3
+ /** Entry kinds. `task_history` is a legacy alias the wire still accepts. */
4
4
  export const EntryTypes = {
5
5
  MESSAGE: 'message',
6
6
  NOTIFICATION: 'notification',
7
7
  ARTIFACT: 'artifact',
8
8
  TASK_HISTORY: 'task_history',
9
9
  };
10
- export const ContentTypes = {
11
- TEXT: 'text',
12
- OPERATION: 'operation',
13
- CONTEXT: 'context',
14
- RESULT: 'result',
15
- TASK_UPDATE: 'task_update',
16
- THOUGHT: 'thought',
17
- };
18
10
  export const ContextProperties = {
19
11
  HISTORY: 'history',
20
12
  AGREEMENTS: 'agreements',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziggs-ai/agent-sdk",
3
- "version": "0.38.1",
3
+ "version": "0.38.2",
4
4
  "description": "Agent framework SDK for building autonomous agents on the Ziggs platform",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -26,7 +26,8 @@
26
26
  "@anthropic-ai/claude-agent-sdk": "^0.3.284",
27
27
  "@anthropic-ai/sdk": "^0.110.0",
28
28
  "@modelcontextprotocol/sdk": "^1.29.0",
29
- "@ziggs-ai/api-client": "0.37.1",
29
+ "@ziggs-ai/api-client": "0.37.4",
30
+ "@ziggs-ai/contracts": "^0.23.3",
30
31
  "ajv": "^8.17.1",
31
32
  "dotenv": "^17.2.3",
32
33
  "openai": "^4.0.0",