@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.
- package/README.md +7 -5
- package/package.json +2 -2
- package/src/AgentHost.ts +165 -12
- package/src/adapters/OpenAIAdapter.ts +21 -0
- package/src/agent/Agent.ts +5 -2
- package/src/cognition/validateContext.ts +1 -1
- package/src/context/batch.ts +3 -3
- package/src/context/classifyEnvelope.ts +2 -2
- package/src/context/routingLabels.ts +1 -1
- package/src/formatters/AgreementFormatter.ts +5 -5
- package/src/formatters/HistoryFormatter.ts +3 -3
- package/src/index.ts +25 -4
- package/src/ingress/normalizeIncoming.ts +50 -7
- package/src/pricing/fleetDefaults.ts +218 -0
- package/src/pricing/fleetEvalFree.ts +24 -0
- package/src/pricing/fleetFreeTierA.gen.ts +12 -0
- package/src/pricing/fleetTierByAgentId.gen.ts +1022 -0
- package/src/runtime/AgentMachine.ts +68 -2
- package/src/runtime/PromptBuilder.ts +25 -23
- package/src/runtime/buildOutcome.ts +33 -3
- package/src/runtime/defaults.ts +3 -0
- package/src/runtime/runTurn.ts +115 -61
- package/src/runtime/validateWorkflow.ts +16 -0
- package/src/server/EventQueue.ts +14 -0
- package/src/server/InboxCatchUp.ts +251 -0
- package/src/server/SeenMessages.ts +27 -0
- package/src/server/ZiggsEffectHandler.ts +82 -8
- package/src/server/agreements/AgreementService.ts +7 -1
- package/src/server/createHealthServer.ts +79 -2
- package/src/server/runLauncher.ts +40 -25
- package/src/server/tasks/TaskService.ts +4 -5
- package/src/server/tasks/index.ts +0 -3
- package/src/server/telemetryIngest.ts +91 -0
- package/src/server/tools/index.ts +46 -0
- package/src/server/{tasks → tools/tier1}/protocolRunner.ts +52 -20
- package/src/server/{tasks → tools/tier1}/protocolTools.ts +6 -3
- package/src/server/tools/tier2/connectionTools.ts +75 -0
- package/src/server/tools/tier2/contextTools.ts +74 -0
- package/src/server/tools/tier2/discoveryTools.ts +34 -0
- package/src/server/tools/tier2/marketplaceTools.ts +25 -0
- package/src/server/{tasks → tools/tier2}/paymentTools.ts +74 -37
- package/src/server/ziggsconnect/ZiggsConnectClient.ts +126 -0
- package/src/server/ziggscontext/ZiggsContextClient.ts +137 -0
- package/src/server/ziggspay/ZiggsPayClient.ts +12 -12
- package/src/shared/types.ts +0 -2
- package/src/tools/index.ts +2 -0
- package/src/tools/recordReport.ts +82 -0
- package/src/types.ts +47 -8
- package/src/tasks/taskCore.ts +0 -139
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import { OPEN_AGREEMENT_TARGET } from '
|
|
1
|
+
import { OPEN_AGREEMENT_TARGET } from '@ziggs-ai/api-client';
|
|
2
|
+
|
|
3
|
+
/** Backend wire operations that map to FSM `proposal-resolved`. */
|
|
4
|
+
const PROPOSAL_RESOLVED_OPERATIONS = new Set([
|
|
5
|
+
'proposal_approved',
|
|
6
|
+
'proposal_rejected',
|
|
7
|
+
'proposal_approved_execute',
|
|
8
|
+
]);
|
|
2
9
|
|
|
3
10
|
export interface NormalizedEvent {
|
|
4
11
|
chatId: string | null;
|
|
@@ -7,7 +14,9 @@ export interface NormalizedEvent {
|
|
|
7
14
|
senderType?: string;
|
|
8
15
|
receiverId?: string;
|
|
9
16
|
timestamp: number;
|
|
10
|
-
type: 'task_result' | 'message';
|
|
17
|
+
type: 'task_result' | 'message' | 'agreement_lifecycle';
|
|
18
|
+
operation?: string;
|
|
19
|
+
agreementId?: string;
|
|
11
20
|
result?: unknown;
|
|
12
21
|
text?: string;
|
|
13
22
|
};
|
|
@@ -16,10 +25,10 @@ export interface NormalizedEvent {
|
|
|
16
25
|
}
|
|
17
26
|
|
|
18
27
|
interface WireParties {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
28
|
+
creator?: string;
|
|
29
|
+
provider?: string;
|
|
30
|
+
payer?: string;
|
|
31
|
+
proposedTo?: string;
|
|
23
32
|
}
|
|
24
33
|
|
|
25
34
|
interface WireTask {
|
|
@@ -42,6 +51,8 @@ interface WireMetadata {
|
|
|
42
51
|
content_type?: string;
|
|
43
52
|
contentType?: string;
|
|
44
53
|
receiverId?: string;
|
|
54
|
+
operation?: string;
|
|
55
|
+
agreementId?: string;
|
|
45
56
|
sender?: { id?: string; type?: string };
|
|
46
57
|
receiver?: { id?: string };
|
|
47
58
|
to?: { id?: string };
|
|
@@ -79,6 +90,16 @@ function isRelevantForAgent(ids: (string | null | undefined)[], ownAgentId: stri
|
|
|
79
90
|
return ids.includes(ownAgentId) || ids.includes(OPEN_AGREEMENT_TARGET);
|
|
80
91
|
}
|
|
81
92
|
|
|
93
|
+
function isAgreementLifecycleNotification(metadata: WireMetadata): boolean {
|
|
94
|
+
const entryType = metadata.entryType || 'message';
|
|
95
|
+
const operation = metadata.operation;
|
|
96
|
+
return (
|
|
97
|
+
entryType === 'notification' &&
|
|
98
|
+
typeof operation === 'string' &&
|
|
99
|
+
PROPOSAL_RESOLVED_OPERATIONS.has(operation)
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
82
103
|
export function normalizeIncomingEvent({ text, metadata = {}, ownAgentId = null }: NormalizeArgs): NormalizedEvent {
|
|
83
104
|
const taskData = metadata.task || null;
|
|
84
105
|
const chatId = normalizeChatId(metadata);
|
|
@@ -92,11 +113,33 @@ export function normalizeIncomingEvent({ text, metadata = {}, ownAgentId = null
|
|
|
92
113
|
timestamp: Date.now(),
|
|
93
114
|
};
|
|
94
115
|
|
|
116
|
+
if (isAgreementLifecycleNotification(metadata)) {
|
|
117
|
+
const relevant =
|
|
118
|
+
!ownAgentId ||
|
|
119
|
+
!receiverId ||
|
|
120
|
+
receiverId === ownAgentId ||
|
|
121
|
+
receiverId === OPEN_AGREEMENT_TARGET;
|
|
122
|
+
const agreementId =
|
|
123
|
+
typeof metadata.agreementId === 'string' ? metadata.agreementId : '';
|
|
124
|
+
return {
|
|
125
|
+
chatId,
|
|
126
|
+
event: {
|
|
127
|
+
...base,
|
|
128
|
+
type: 'agreement_lifecycle',
|
|
129
|
+
operation: metadata.operation,
|
|
130
|
+
agreementId,
|
|
131
|
+
text,
|
|
132
|
+
},
|
|
133
|
+
shouldProcess: relevant,
|
|
134
|
+
reason: relevant ? null : 'message_not_targeted_to_agent',
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
95
138
|
if (isTaskRelated(metadata, taskData)) {
|
|
96
139
|
const receiverFromMeta = metadata.receiver?.id || metadata.receiverId || null;
|
|
97
140
|
const parties = taskData!.agreement?.parties ?? {};
|
|
98
141
|
const candidateIds = [
|
|
99
|
-
parties.
|
|
142
|
+
parties.creator, parties.provider, parties.payer, parties.proposedTo,
|
|
100
143
|
taskData!.agentId, taskData!.executorId, taskData!.payerId, taskData!.proposedTo, taskData!.createdBy,
|
|
101
144
|
receiverFromMeta,
|
|
102
145
|
].filter(Boolean);
|
|
@@ -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;
|