@ziggs-ai/agent-sdk 0.12.0 → 0.14.0

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.
Files changed (41) hide show
  1. package/dist/AgentHost.js +4 -1
  2. package/dist/agent/ClaudeSdkAgent.js +2 -2
  3. package/dist/agent/claudeCognition.js +12 -0
  4. package/dist/agent/claudeSdkTools.js +5 -1
  5. package/dist/cognition/validateContext.js +4 -1
  6. package/dist/context/batch.d.ts +3 -0
  7. package/dist/context/batch.js +8 -5
  8. package/dist/context/classifyEnvelope.js +4 -5
  9. package/dist/context/routingLabels.js +2 -3
  10. package/dist/formatters/AgreementFormatter.d.ts +7 -1
  11. package/dist/formatters/AgreementFormatter.js +17 -8
  12. package/dist/formatters/HistoryFormatter.d.ts +5 -0
  13. package/dist/formatters/HistoryFormatter.js +16 -7
  14. package/dist/index.d.ts +2 -1
  15. package/dist/index.js +2 -1
  16. package/dist/ingress/normalizeIncoming.d.ts +3 -8
  17. package/dist/pricing/fleetDefaults.d.ts +0 -1
  18. package/dist/pricing/fleetDefaults.js +7 -12
  19. package/dist/runtime/PromptBuilder.js +19 -21
  20. package/dist/runtime/buildOutcome.js +4 -4
  21. package/dist/runtime/kickoff.d.ts +17 -4
  22. package/dist/runtime/kickoff.js +55 -15
  23. package/dist/runtime/mandateDeclaration.d.ts +9 -0
  24. package/dist/runtime/mandateDeclaration.js +62 -0
  25. package/dist/runtime/runTurn.js +8 -0
  26. package/dist/server/agreements/AgreementService.d.ts +14 -12
  27. package/dist/server/agreements/AgreementService.js +15 -15
  28. package/dist/server/inboxLoop.js +19 -0
  29. package/dist/server/proactive/ProactiveTrigger.d.ts +7 -1
  30. package/dist/server/proactive/ProactiveTrigger.js +2 -2
  31. package/dist/server/tools/index.d.ts +1 -1
  32. package/dist/server/tools/index.js +1 -1
  33. package/dist/server/tools/tier1/protocolRunner.js +14 -8
  34. package/dist/server/tools/tier1/protocolTools.js +8 -3
  35. package/dist/server/tools/tier2/linkTools.d.ts +1 -1
  36. package/dist/server/tools/tier2/linkTools.js +11 -9
  37. package/dist/tools/capabilityAdapter.js +10 -7
  38. package/dist/tools/toolCreds.d.ts +37 -0
  39. package/dist/tools/toolCreds.js +49 -0
  40. package/dist/types.d.ts +2 -6
  41. package/package.json +2 -2
@@ -0,0 +1,49 @@
1
+ /**
2
+ * toolCreds.ts — the credentials a tool acts under, read off its own context.
3
+ *
4
+ * A custom tool builds `{ operatorKey, agentId }` by hand and stops there, so
5
+ * every call it makes runs on the narrowest reach fence there is: the agent's
6
+ * own org. `AgentHost` already threads the wake's lane into the tool context
7
+ * (as `chatId` / `sessionId`, which is what the capability adapter reads), and
8
+ * the backend's fence is "own org ∪ the orgs of the parties to this lane" — so
9
+ * a tool that does not pass it loses reach it is entitled to, and loses it
10
+ * SILENTLY: enumerations come back short rather than refused.
11
+ *
12
+ * Measured on a five-node graph run: a coordinator asking which tasks it had
13
+ * created saw 0 of 5 with no lane and 5 of 5 with its own lane declared. The
14
+ * `task_list({ createdByMe: true })` convergence check that `lab-hirer`'s prompt
15
+ * recommends would therefore answer "nothing yet" and rebuild the whole graph,
16
+ * billing every worker twice.
17
+ *
18
+ * So: one reader, used by every tool, rather than a field each author has to
19
+ * remember. Omitting the lane can only narrow reach, never widen it, which is
20
+ * why forgetting it never fails loudly.
21
+ */
22
+ const str = (ctx, key) => {
23
+ const value = ctx?.[key];
24
+ return typeof value === 'string' && value.trim() ? value : undefined;
25
+ };
26
+ /**
27
+ * The wake's lane, as the backend's `X-Ziggs-Lane` expects it: a chat id, or
28
+ * `agrn-<agreementId>` for an agreement lane. Undefined when the tool is
29
+ * running outside any lane (a bootstrap sweep, a test), which the fence reads
30
+ * as "own org only".
31
+ */
32
+ export function laneFromToolContext(ctx) {
33
+ return str(ctx, 'chatId') ?? str(ctx, 'sessionId');
34
+ }
35
+ /**
36
+ * The creds a tool should act under. Throws when the context is missing what a
37
+ * call needs, rather than building something that 401s later somewhere else.
38
+ */
39
+ export function credsFromToolContext(ctx, toolName) {
40
+ const where = toolName ? `${toolName}: ` : '';
41
+ const operatorKey = str(ctx, 'operatorKey');
42
+ if (!operatorKey)
43
+ throw new Error(`${where}operatorKey missing from tool context`);
44
+ const agentId = str(ctx, 'agentId');
45
+ if (!agentId)
46
+ throw new Error(`${where}agentId missing from tool context`);
47
+ const laneId = laneFromToolContext(ctx);
48
+ return { operatorKey, agentId, ...(laneId ? { laneId } : {}) };
49
+ }
package/dist/types.d.ts CHANGED
@@ -4,15 +4,11 @@
4
4
  * One outcome vocabulary, one ctx shape, one transition signature.
5
5
  * Every state — parked or thinking — re-enters with exactly one Outcome.
6
6
  */
7
+ import type { AgreementParties } from '@ziggs-ai/api-client';
7
8
  import type { AgentNeed } from './tools/needs.js';
8
9
  export interface AgreementRef {
9
10
  agreementId: string;
10
- parties?: {
11
- creator?: string;
12
- provider?: string;
13
- payer?: string;
14
- proposedTo?: string;
15
- };
11
+ parties?: AgreementParties;
16
12
  proposal?: {
17
13
  status?: 'pending' | 'approved' | 'rejected' | 'cancelled';
18
14
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziggs-ai/agent-sdk",
3
- "version": "0.12.0",
3
+ "version": "0.14.0",
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,7 @@
26
26
  "@anthropic-ai/claude-agent-sdk": "^0.3.204",
27
27
  "@anthropic-ai/sdk": "^0.110.0",
28
28
  "@modelcontextprotocol/sdk": "^1.29.0",
29
- "@ziggs-ai/api-client": "0.11.0",
29
+ "@ziggs-ai/api-client": "0.13.0",
30
30
  "ajv": "^8.17.1",
31
31
  "dotenv": "^17.2.3",
32
32
  "openai": "^4.0.0",