@ziggs-ai/agent-sdk 0.1.3 → 0.1.5

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 (98) hide show
  1. package/README.md +3 -1
  2. package/package.json +9 -4
  3. package/src/AgentHost.ts +495 -0
  4. package/src/adapters/OpenAIAdapter.ts +146 -0
  5. package/src/agent/Agent.ts +101 -0
  6. package/src/cognition/validateContext.ts +95 -0
  7. package/src/context/applyEffects.ts +80 -0
  8. package/src/context/batch.ts +17 -0
  9. package/src/context/classifyEnvelope.ts +38 -0
  10. package/src/context/routingLabels.ts +46 -0
  11. package/src/defineAgent.ts +62 -0
  12. package/src/formatters/AgreementFormatter.ts +111 -0
  13. package/src/formatters/HistoryFormatter.ts +166 -0
  14. package/src/formatters/index.ts +2 -0
  15. package/src/index.ts +105 -0
  16. package/src/ingress/normalizeIncoming.ts +162 -0
  17. package/src/memory/MemoryStore.ts +104 -0
  18. package/src/pricing/fleetDefaults.ts +218 -0
  19. package/src/pricing/fleetEvalFree.ts +24 -0
  20. package/src/pricing/fleetFreeTierA.gen.ts +12 -0
  21. package/src/pricing/fleetTierByAgentId.gen.ts +1022 -0
  22. package/src/runtime/AgentMachine.ts +364 -0
  23. package/src/runtime/PromptBuilder.ts +463 -0
  24. package/src/runtime/buildOutcome.ts +518 -0
  25. package/src/runtime/defaults.ts +75 -0
  26. package/src/runtime/runTurn.ts +691 -0
  27. package/src/runtime/validateWorkflow.ts +181 -0
  28. package/src/server/ConnectionPool.ts +155 -0
  29. package/src/server/EventQueue.ts +133 -0
  30. package/src/server/InboxCatchUp.ts +251 -0
  31. package/src/server/OutboxBuffer.ts +90 -0
  32. package/src/server/SeenMessages.ts +27 -0
  33. package/src/server/ZiggsEffectHandler.ts +409 -0
  34. package/src/server/agreements/AgreementService.ts +117 -0
  35. package/src/server/createHealthServer.ts +85 -0
  36. package/src/server/proactive/ProactiveTrigger.ts +83 -0
  37. package/src/server/runLauncher.ts +146 -0
  38. package/src/server/tasks/TaskService.ts +110 -0
  39. package/src/server/tasks/index.ts +1 -0
  40. package/src/server/telemetryIngest.ts +91 -0
  41. package/src/server/tools/index.ts +46 -0
  42. package/src/server/tools/tier1/protocolRunner.ts +133 -0
  43. package/src/server/tools/tier1/protocolTools.ts +99 -0
  44. package/src/server/tools/tier2/connectionTools.ts +75 -0
  45. package/src/server/tools/tier2/contextTools.ts +74 -0
  46. package/src/server/tools/tier2/discoveryTools.ts +34 -0
  47. package/src/server/tools/tier2/marketplaceTools.ts +25 -0
  48. package/src/server/tools/tier2/paymentTools.ts +193 -0
  49. package/src/server/ziggsconnect/ZiggsConnectClient.ts +126 -0
  50. package/src/server/ziggscontext/ZiggsContextClient.ts +137 -0
  51. package/src/server/ziggspay/ZiggsPayClient.ts +193 -0
  52. package/src/shared/ids.ts +3 -0
  53. package/src/shared/runtimeLog.ts +72 -0
  54. package/src/shared/types.ts +29 -0
  55. package/src/tasks/protocolRegistry.ts +25 -0
  56. package/src/tools/ToolManager.ts +95 -0
  57. package/src/tools/{ToolProvider.js → ToolProvider.ts} +5 -15
  58. package/src/tools/defineTool.ts +90 -0
  59. package/src/tools/index.ts +5 -0
  60. package/src/types.ts +407 -0
  61. package/src/utils/jsonExtractor.ts +100 -0
  62. package/src/ConnectionPool.js +0 -133
  63. package/src/adapters/OpenAIAdapter.js +0 -73
  64. package/src/agent/Agent.js +0 -121
  65. package/src/agent/EventQueue.js +0 -68
  66. package/src/agent/OutboxBuffer.js +0 -62
  67. package/src/cognition/PromptBuilder.js +0 -312
  68. package/src/cognition/resolveActionTool.js +0 -12
  69. package/src/cognition/runTurn.js +0 -578
  70. package/src/context/applyEffects.js +0 -133
  71. package/src/context/batch.js +0 -25
  72. package/src/context/classifyEnvelope.js +0 -82
  73. package/src/context/routingLabels.js +0 -54
  74. package/src/createHealthServer.js +0 -28
  75. package/src/formatters/HistoryFormatter.js +0 -257
  76. package/src/formatters/TaskFormatter.js +0 -180
  77. package/src/formatters/index.js +0 -9
  78. package/src/index.js +0 -76
  79. package/src/ingress/normalizeIncoming.js +0 -70
  80. package/src/runLauncher.js +0 -159
  81. package/src/shared/ids.js +0 -7
  82. package/src/shared/types.js +0 -86
  83. package/src/tasks/TaskService.js +0 -247
  84. package/src/tasks/index.js +0 -9
  85. package/src/tasks/taskCore.js +0 -229
  86. package/src/tasks/taskProtocolRegistry.js +0 -22
  87. package/src/tasks/taskProtocolRunner.js +0 -107
  88. package/src/tasks/taskProtocolTools.js +0 -87
  89. package/src/tools/ToolManager.js +0 -79
  90. package/src/tools/defineTool.js +0 -82
  91. package/src/tools/index.js +0 -11
  92. package/src/utils/jsonExtractor.js +0 -139
  93. package/src/workflow/AgentMachine.js +0 -250
  94. package/src/workflow/WorkflowRuntime.js +0 -63
  95. package/src/workflow/dsl.js +0 -287
  96. package/src/workflow/motifs.js +0 -435
  97. package/src/ziggs/runtime.js +0 -192
  98. /package/src/adapters/{index.js → index.ts} +0 -0
@@ -0,0 +1,218 @@
1
+ /**
2
+ * ZIG-368 — default paid pricing for Ziggs-operated (first-party) agents.
3
+ * Prices are in wallet cents (1 ZIG = 100 cents).
4
+ */
5
+ import { FLEET_TIER_BY_AGENT_ID, type FleetPricingTier } from './fleetTierByAgentId.gen.js';
6
+ import { FREE_TIER_A_AGENT_IDS } from './fleetFreeTierA.gen.js';
7
+ import { isEvalFreeExecutor } from './fleetEvalFree.js';
8
+
9
+ export const ZIGGS_OPERATOR_CUT_BPS = 1000; // 10%
10
+
11
+ export const TIER_PRICE_CENTS: Record<FleetPricingTier, number> = {
12
+ A: 200, // 2 ZIG / call
13
+ B: 500, // 5 ZIG / call
14
+ C: 1500, // 15 ZIG / job (orchestrator, charged once at top)
15
+ D: 100, // 1 ZIG / call (simulated)
16
+ };
17
+
18
+ const ZIGGS_ORCHESTRATOR_IDS = new Set(['ziggs-agent']);
19
+
20
+ const PING_DESCRIPTION_PATTERN =
21
+ /\b(ping|health\s*check|healthcheck|liveness|readiness|heartbeat)\b/i;
22
+
23
+ const TRIVIAL_LOOKUP_DESCRIPTION_PATTERN =
24
+ /\b(what\s+time|current\s+time|local\s+time|world\s+clock|timezone|time\s+zone|weather|forecast|temperature|uv\s+index)\b/i;
25
+
26
+ export function resolveFleetTier(agentId: string): FleetPricingTier | null {
27
+ if (!agentId || typeof agentId !== 'string') return null;
28
+ return FLEET_TIER_BY_AGENT_ID[agentId] ?? null;
29
+ }
30
+
31
+ export function isFirstPartyFleetAgent(agentId: string): boolean {
32
+ return resolveFleetTier(agentId) != null;
33
+ }
34
+
35
+ export function tierPriceCents(tier: FleetPricingTier): number {
36
+ return TIER_PRICE_CENTS[tier];
37
+ }
38
+
39
+ export function isZiggsOrchestrator(agentId: string): boolean {
40
+ return ZIGGS_ORCHESTRATOR_IDS.has(agentId);
41
+ }
42
+
43
+ export function isFreeAllowlistedExecutor(
44
+ executorId: string,
45
+ description?: string | null,
46
+ ): boolean {
47
+ if (!executorId) return false;
48
+ if (isEvalFreeExecutor(executorId)) return true;
49
+ if (FREE_TIER_A_AGENT_IDS.has(executorId)) return true;
50
+ if (description && PING_DESCRIPTION_PATTERN.test(description)) return true;
51
+ if (
52
+ description &&
53
+ TRIVIAL_LOOKUP_DESCRIPTION_PATTERN.test(description) &&
54
+ FREE_TIER_A_AGENT_IDS.has(executorId)
55
+ ) {
56
+ return true;
57
+ }
58
+ return false;
59
+ }
60
+
61
+ export function resolveDefaultPriceCentsForExecutor(
62
+ executorId: string,
63
+ description?: string | null,
64
+ ): number | null {
65
+ if (isFreeAllowlistedExecutor(executorId, description)) return 0;
66
+ const tier = resolveFleetTier(executorId);
67
+ if (!tier) return null;
68
+ return tierPriceCents(tier);
69
+ }
70
+
71
+ export interface ProtocolPricingPayload {
72
+ price?: number | null;
73
+ description?: string;
74
+ agreementDescription?: string;
75
+ proposedTo?: string;
76
+ providerId?: string;
77
+ executorId?: string;
78
+ parentAgreementId?: string;
79
+ parentTaskId?: string;
80
+ [key: string]: unknown;
81
+ }
82
+
83
+ /**
84
+ * Apply ZIG-368 defaults when `price` is omitted (null/undefined).
85
+ * Explicit `price: 0` is kept (free-on-purpose).
86
+ */
87
+ export function applyFleetAgreementPricing(
88
+ operation: 'agreement-propose' | 'agreement-subcontract',
89
+ payload: ProtocolPricingPayload,
90
+ actingAgentId: string,
91
+ ): ProtocolPricingPayload {
92
+ if (payload.price != null && payload.price !== undefined) {
93
+ return payload;
94
+ }
95
+
96
+ const next = { ...payload };
97
+ const scopeDescription = next.description ?? next.agreementDescription;
98
+
99
+ if (operation === 'agreement-subcontract') {
100
+ const executorId = String(next.executorId ?? '');
101
+ if (next.parentAgreementId) {
102
+ // Paid parent scope: no second user hold — allocate from parent budget (recordAllocation).
103
+ const cents = resolveDefaultPriceCentsForExecutor(executorId, scopeDescription);
104
+ next.price = cents ?? 0;
105
+ return next;
106
+ }
107
+ const cents = resolveDefaultPriceCentsForExecutor(executorId, scopeDescription);
108
+ if (cents != null) next.price = cents;
109
+ return next;
110
+ }
111
+
112
+ // agreement-propose
113
+ if (next.parentAgreementId) {
114
+ return next;
115
+ }
116
+
117
+ const proposedTo = next.proposedTo != null ? String(next.proposedTo) : '';
118
+ const providerId = next.providerId != null ? String(next.providerId) : '';
119
+
120
+ // Ziggs scope proposal to human user — 15 ZIG once at top.
121
+ if (
122
+ isZiggsOrchestrator(actingAgentId) &&
123
+ proposedTo &&
124
+ !isFirstPartyFleetAgent(proposedTo)
125
+ ) {
126
+ next.price = TIER_PRICE_CENTS.C;
127
+ return next;
128
+ }
129
+
130
+ // Tier C orchestrator proposing scope to a user (non-ziggs fleet orchestrators).
131
+ const actingTier = resolveFleetTier(actingAgentId);
132
+ if (actingTier === 'C' && proposedTo && !isFirstPartyFleetAgent(proposedTo)) {
133
+ next.price = TIER_PRICE_CENTS.C;
134
+ return next;
135
+ }
136
+
137
+ // Matchmaking: propose directly to a fleet specialist with tier list price.
138
+ const specialistId = providerId || (isFirstPartyFleetAgent(proposedTo) ? proposedTo : '');
139
+ if (specialistId) {
140
+ const cents = resolveDefaultPriceCentsForExecutor(specialistId, scopeDescription);
141
+ if (cents != null) next.price = cents;
142
+ }
143
+
144
+ return next;
145
+ }
146
+
147
+ /** Default tier price when a fleet agent counters without an explicit `price`. */
148
+ export function applyFleetCounterPricing(
149
+ payload: ProtocolPricingPayload,
150
+ actingAgentId: string,
151
+ ): ProtocolPricingPayload {
152
+ if (payload.price != null && payload.price !== undefined) {
153
+ return payload;
154
+ }
155
+ const cents = resolveDefaultPriceCentsForExecutor(
156
+ actingAgentId,
157
+ payload.description ?? payload.agreementDescription,
158
+ );
159
+ if (cents == null) return payload;
160
+ return { ...payload, price: cents };
161
+ }
162
+
163
+ /** User or agent direct-create / marketplace: default from provider specialist. */
164
+ export function resolveDefaultPriceForProvider(
165
+ providerId: string,
166
+ description?: string | null,
167
+ explicitPrice?: number | null,
168
+ ): number | null {
169
+ if (typeof explicitPrice === 'number') return explicitPrice;
170
+ return resolveDefaultPriceCentsForExecutor(providerId, description);
171
+ }
172
+
173
+ /**
174
+ * Infer fleet actor when tool context omits agentId (ZIG-368 safety net).
175
+ */
176
+ export function inferFleetPricingActorId(payload: ProtocolPricingPayload): string | null {
177
+ const executor = payload.executorId != null ? String(payload.executorId) : '';
178
+ if (executor && isFirstPartyFleetAgent(executor)) return executor;
179
+ const provider = payload.providerId != null ? String(payload.providerId) : '';
180
+ if (provider && isFirstPartyFleetAgent(provider)) return provider;
181
+ const proposed = payload.proposedTo != null ? String(payload.proposedTo) : '';
182
+ if (proposed && isFirstPartyFleetAgent(proposed)) return proposed;
183
+ return null;
184
+ }
185
+
186
+ /** Apply fleet defaults with optional acting agent (falls back to payload inference). */
187
+ export function applyFleetPricingForProtocol(
188
+ operation: 'agreement-propose' | 'agreement-subcontract',
189
+ payload: ProtocolPricingPayload,
190
+ actingAgentId: string | null,
191
+ ): ProtocolPricingPayload {
192
+ const actor = actingAgentId?.trim() || inferFleetPricingActorId(payload);
193
+ if (!actor) {
194
+ if (operation === 'agreement-propose') {
195
+ const specialist =
196
+ (payload.providerId != null ? String(payload.providerId) : '') ||
197
+ (payload.proposedTo != null && isFirstPartyFleetAgent(String(payload.proposedTo))
198
+ ? String(payload.proposedTo)
199
+ : '');
200
+ if (specialist) {
201
+ const cents = resolveDefaultPriceCentsForExecutor(
202
+ specialist,
203
+ payload.description ?? (payload.agreementDescription as string | undefined),
204
+ );
205
+ if (cents != null) return { ...payload, price: cents };
206
+ }
207
+ }
208
+ if (operation === 'agreement-subcontract' && payload.executorId) {
209
+ const cents = resolveDefaultPriceCentsForExecutor(
210
+ String(payload.executorId),
211
+ payload.description,
212
+ );
213
+ if (cents != null) return { ...payload, price: cents };
214
+ }
215
+ return payload;
216
+ }
217
+ return applyFleetAgreementPricing(operation, payload, actor);
218
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * ZIG-395 — eval/harness free pricing via env flag (no SANDBOX id-shape regex).
3
+ */
4
+
5
+ /** Capability-probe + test harness agents (agents/test/). */
6
+ export const EVAL_HARNESS_AGENT_IDS = new Set([
7
+ 'minimal-context-agent',
8
+ 'forwarding-agent',
9
+ 'failing-agent',
10
+ 'messaging-only-agent',
11
+ 'principal-agent',
12
+ 'capability-probe-agent',
13
+ ]);
14
+
15
+ export function isEvalFreePricingEnabled(): boolean {
16
+ return process.env.FLEET_EVAL_FREE_PRICING === 'true';
17
+ }
18
+
19
+ export function isEvalFreeExecutor(agentId: string): boolean {
20
+ if (!isEvalFreePricingEnabled() || !agentId) return false;
21
+ if (agentId === 'eval-user') return true;
22
+ if (agentId.endsWith('--eval')) return true;
23
+ return EVAL_HARNESS_AGENT_IDS.has(agentId);
24
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * AUTO-GENERATED by scripts/build-fleet-tier-map.mjs — do not edit by hand.
3
+ * ZIG-368: Tier A trivial public lookups (free when price omitted).
4
+ */
5
+ export const FREE_TIER_A_AGENT_IDS = new Set<string>([
6
+ "site-health-checker",
7
+ "timezone-expert",
8
+ "uv-index-advisor",
9
+ "weather-forecaster"
10
+ ]);
11
+
12
+ export const FREE_TIER_A_COUNT = 4;