@ziggs-ai/agent-sdk 0.1.4 → 0.1.6

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 (49) hide show
  1. package/README.md +7 -5
  2. package/package.json +2 -2
  3. package/src/AgentHost.ts +165 -12
  4. package/src/adapters/OpenAIAdapter.ts +21 -0
  5. package/src/agent/Agent.ts +5 -2
  6. package/src/cognition/validateContext.ts +1 -1
  7. package/src/context/batch.ts +3 -3
  8. package/src/context/classifyEnvelope.ts +2 -2
  9. package/src/context/routingLabels.ts +1 -1
  10. package/src/formatters/AgreementFormatter.ts +5 -5
  11. package/src/formatters/HistoryFormatter.ts +3 -3
  12. package/src/index.ts +25 -4
  13. package/src/ingress/normalizeIncoming.ts +50 -7
  14. package/src/pricing/fleetDefaults.ts +218 -0
  15. package/src/pricing/fleetEvalFree.ts +24 -0
  16. package/src/pricing/fleetFreeTierA.gen.ts +12 -0
  17. package/src/pricing/fleetTierByAgentId.gen.ts +1022 -0
  18. package/src/runtime/AgentMachine.ts +68 -2
  19. package/src/runtime/PromptBuilder.ts +25 -23
  20. package/src/runtime/buildOutcome.ts +33 -3
  21. package/src/runtime/defaults.ts +3 -0
  22. package/src/runtime/runTurn.ts +115 -61
  23. package/src/runtime/validateWorkflow.ts +16 -0
  24. package/src/server/EventQueue.ts +14 -0
  25. package/src/server/InboxCatchUp.ts +251 -0
  26. package/src/server/SeenMessages.ts +27 -0
  27. package/src/server/ZiggsEffectHandler.ts +82 -8
  28. package/src/server/agreements/AgreementService.ts +7 -1
  29. package/src/server/createHealthServer.ts +79 -2
  30. package/src/server/runLauncher.ts +40 -25
  31. package/src/server/tasks/TaskService.ts +4 -5
  32. package/src/server/tasks/index.ts +0 -3
  33. package/src/server/telemetryIngest.ts +91 -0
  34. package/src/server/tools/index.ts +46 -0
  35. package/src/server/{tasks → tools/tier1}/protocolRunner.ts +52 -20
  36. package/src/server/{tasks → tools/tier1}/protocolTools.ts +6 -3
  37. package/src/server/tools/tier2/connectionTools.ts +75 -0
  38. package/src/server/tools/tier2/contextTools.ts +74 -0
  39. package/src/server/tools/tier2/discoveryTools.ts +34 -0
  40. package/src/server/tools/tier2/marketplaceTools.ts +25 -0
  41. package/src/server/{tasks → tools/tier2}/paymentTools.ts +74 -37
  42. package/src/server/ziggsconnect/ZiggsConnectClient.ts +126 -0
  43. package/src/server/ziggscontext/ZiggsContextClient.ts +137 -0
  44. package/src/server/ziggspay/ZiggsPayClient.ts +12 -12
  45. package/src/shared/types.ts +0 -2
  46. package/src/tools/index.ts +2 -0
  47. package/src/tools/recordReport.ts +82 -0
  48. package/src/types.ts +47 -8
  49. package/src/tasks/taskCore.ts +0 -139
package/src/types.ts CHANGED
@@ -10,10 +10,10 @@
10
10
  export interface AgreementRef {
11
11
  agreementId: string;
12
12
  parties?: {
13
- creatorId?: string;
14
- providerId?: string;
15
- payerId?: string;
16
- proposedToId?: string;
13
+ creator?: string;
14
+ provider?: string;
15
+ payer?: string;
16
+ proposedTo?: string;
17
17
  };
18
18
  proposal?: { status?: 'pending' | 'approved' | 'rejected' | 'cancelled' };
19
19
  money?: { price?: number; paymentStatus?: string };
@@ -61,7 +61,7 @@ export type Outcome =
61
61
  | { kind: 'wait' }
62
62
  | { kind: 'timeout' }
63
63
  | { kind: 'message-sent'; text?: string; receiverId?: string }
64
- | { kind: 'message-received'; text?: string; senderId?: string }
64
+ | { kind: 'message-received'; text?: string; senderId?: string; senderType?: string }
65
65
  | { kind: 'task-assigned'; task: TaskRef }
66
66
  | { kind: 'task-delegated'; task: TaskRef }
67
67
  | { kind: 'task-closed'; status: 'completed' | 'failed'; result?: unknown }
@@ -166,6 +166,13 @@ export interface Action {
166
166
  prompt: ActionPrompt;
167
167
  tool?: string | null;
168
168
  produces: Produces;
169
+ /**
170
+ * When true, the tool loop exits immediately after this action's tool result,
171
+ * even if the result is non-terminal. Prevents the LLM from issuing additional
172
+ * tool calls in the same turn (e.g. calling agreement_subcontract right after
173
+ * agent_search before the FSM can route to evaluatingCandidates).
174
+ */
175
+ terminatesLoop?: boolean;
169
176
  }
170
177
 
171
178
  export interface Transition {
@@ -283,6 +290,7 @@ import type { MemoryStore } from './memory/MemoryStore.js';
283
290
  export type EffectKind =
284
291
  | 'read-context'
285
292
  | 'llm-call'
293
+ | 'stream-text'
286
294
  | 'tool-call'
287
295
  | 'send-message'
288
296
  | 'record-event'
@@ -295,9 +303,39 @@ export interface ScopeRef { kind: 'chat' | 'agreement' | 'task' | 'counterparty'
295
303
 
296
304
  export type Effect =
297
305
  | { kind: 'read-context'; sessionId: string; opts?: ReadContextOpts }
298
- | { kind: 'llm-call'; messages: LlmMessage[]; tools: LlmToolSchema[] }
299
- | { kind: 'tool-call'; sessionId: string; name: string; args: unknown; memory?: MemoryStore }
300
- | { kind: 'send-message'; sessionId: string; receiverId: string; text: string }
306
+ | {
307
+ kind: 'llm-call';
308
+ messages: LlmMessage[];
309
+ tools: LlmToolSchema[];
310
+ /** Chat/session id for monitoring ingest (ZIG-360). */
311
+ sessionId?: string;
312
+ /** Per-turn UUID grouping all LLM + tool calls in one turn (ZIG-440). */
313
+ runId?: string;
314
+ /** FSM state name at the time of this call (ZIG-440). */
315
+ stateId?: string;
316
+ }
317
+ | {
318
+ kind: 'stream-text';
319
+ sessionId: string;
320
+ receiverId: string;
321
+ /** Pre-allocated messageId shared across all chunks and the final send-message. */
322
+ messageId: string;
323
+ messages: LlmMessage[];
324
+ }
325
+ | {
326
+ kind: 'tool-call';
327
+ sessionId: string;
328
+ name: string;
329
+ args: unknown;
330
+ memory?: MemoryStore;
331
+ senderId?: string;
332
+ senderType?: string;
333
+ /** Per-turn UUID (ZIG-440). */
334
+ runId?: string;
335
+ /** FSM state name (ZIG-440). */
336
+ stateId?: string;
337
+ }
338
+ | { kind: 'send-message'; sessionId: string; receiverId: string; text: string; messageId?: string }
301
339
  | { kind: 'record-event'; sessionId: string; entry: RecordedEntry }
302
340
  | { kind: 'get-scope'; via: ScopeRef }
303
341
  | { kind: 'list-messages'; chatId: string; after?: string; limit?: number }
@@ -312,6 +350,7 @@ export type Effect =
312
350
  export interface EffectResultMap {
313
351
  'read-context': ContextSnapshot;
314
352
  'llm-call': LlmResponse;
353
+ 'stream-text': { text: string };
315
354
  'tool-call': ToolCallResult;
316
355
  'send-message': { ok: true };
317
356
  'record-event': { ok: true };
@@ -1,139 +0,0 @@
1
- /**
2
- * Canonical Task definitions — states, state machine, shapes, and helpers.
3
- * ⚠️ SYNC: Keep in sync with backend/src/tasks/task-core.ts
4
- * and backend/src/agreements/agreement.schema.ts
5
- */
6
-
7
- export const TaskState = {
8
- PROPOSAL: 'proposal',
9
- ACTIVE: 'active',
10
- COMPLETED: 'completed',
11
- FAILED: 'failed',
12
- CANCELLED: 'cancelled',
13
- } as const;
14
-
15
- export type TaskStateValue = (typeof TaskState)[keyof typeof TaskState];
16
-
17
- export const TASK_STATES: TaskStateValue[] = ['proposal', 'active', 'completed', 'failed', 'cancelled'];
18
- export const TERMINAL_STATES: TaskStateValue[] = ['completed', 'failed', 'cancelled'];
19
-
20
- export const VALID_TRANSITIONS: Partial<Record<TaskStateValue, TaskStateValue[]>> = {
21
- proposal: ['active', 'cancelled'],
22
- active: ['completed', 'failed', 'cancelled'],
23
- };
24
-
25
- export function isTerminal(state: string): boolean {
26
- return TERMINAL_STATES.includes(state as TaskStateValue);
27
- }
28
-
29
- export function canTransitionTo(from: string, to: string): boolean {
30
- if (isTerminal(from)) return false;
31
- const allowed = VALID_TRANSITIONS[from as TaskStateValue];
32
- if (!allowed) return false;
33
- return allowed.includes(to as TaskStateValue);
34
- }
35
-
36
- export function normalizeState(state: string): string {
37
- if (state === 'done') return TaskState.COMPLETED;
38
- if (state === 'error') return TaskState.FAILED;
39
- return state;
40
- }
41
-
42
- export function isValidState(state: string): boolean {
43
- return TASK_STATES.includes(state as TaskStateValue);
44
- }
45
-
46
- // ── Shapes ────────────────────────────────────────────────────────────────────
47
-
48
- export interface PlanStep {
49
- stepId: string;
50
- description?: string;
51
- order?: number;
52
- status?: 'pending' | 'in_progress' | 'completed' | 'skipped';
53
- result?: unknown;
54
- }
55
-
56
- export interface TaskHistoryEntry {
57
- changeType: string;
58
- [key: string]: unknown;
59
- }
60
-
61
- export interface AgreementParties {
62
- creatorId?: string | null;
63
- providerId?: string | null;
64
- payerId?: string | null;
65
- proposedToId?: string | null;
66
- }
67
-
68
- export interface AgreementTerms {
69
- price?: number | null;
70
- lifecycle?: string | null;
71
- expiresAt?: string | null;
72
- maxExecutions?: number | null;
73
- description?: string | null;
74
- }
75
-
76
- export interface AgreementMoney {
77
- price?: number | null;
78
- paymentStatus?: string | null;
79
- }
80
-
81
- export interface AgreementProposal {
82
- status: 'pending' | 'approved' | 'rejected' | null;
83
- respondedBy?: string | null;
84
- proposedAt?: string | null;
85
- respondedAt?: string | null;
86
- }
87
-
88
- export const HistoryChangeType = {
89
- CREATED: 'created',
90
- STATE_CHANGED: 'state_changed',
91
- PROCESSING_CHANGED: 'processing_changed',
92
- PLAN_STEP_CHANGED: 'plan_step_changed',
93
- PLAN_RESTRUCTURED: 'plan_restructured',
94
- PLAN_ACKNOWLEDGED: 'plan_acknowledged',
95
- } as const;
96
-
97
- export type HistoryChangeTypeValue = (typeof HistoryChangeType)[keyof typeof HistoryChangeType];
98
-
99
- export interface Agreement {
100
- agreementId: string;
101
- taskId?: string | null;
102
- rootAgreementId?: string | null;
103
- parentAgreementId?: string | null;
104
- parties: AgreementParties;
105
- terms: AgreementTerms;
106
- money: AgreementMoney;
107
- proposal: AgreementProposal;
108
- status: 'draft' | 'open' | 'active' | 'fulfilled' | 'cancelled' | 'refunded';
109
- createdAt: string;
110
- updatedAt: string;
111
- }
112
-
113
- export interface Task {
114
- taskId: string;
115
- description: string;
116
- agreementId: string;
117
- agreement?: Agreement | null;
118
- state: TaskStateValue;
119
- processing: boolean;
120
- deleted: boolean;
121
- result?: unknown;
122
- errorMessage?: string | null;
123
- createdAt: string;
124
- updatedAt: string;
125
- parentTaskId?: string | null;
126
- rootTaskId?: string | null;
127
- plan?: { steps?: PlanStep[] };
128
- history?: TaskHistoryEntry[];
129
- }
130
-
131
- export interface TaskWithFlags extends Task {
132
- creatorIsYou?: boolean;
133
- providerIsYou?: boolean;
134
- payerIsYou?: boolean;
135
- proposedToIsYou?: boolean;
136
- }
137
-
138
- /** ⚠️ SYNC: Keep in sync with backend and api-client */
139
- export const OPEN_AGREEMENT_TARGET = 'everyone' as const;