@ziggs-ai/api-client 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.
- package/dist/capabilities/agreementVerbs.js +13 -0
- package/dist/capabilities/agreements.js +33 -3
- package/dist/capabilities/context.js +2 -2
- package/dist/capabilities/grants.d.ts +2 -1
- package/dist/capabilities/grants.js +4 -3
- package/dist/capabilities/index.d.ts +1 -0
- package/dist/capabilities/index.js +1 -0
- package/dist/capabilities/introductions.d.ts +6 -0
- package/dist/capabilities/introductions.js +172 -0
- package/dist/capabilities/links.d.ts +1 -0
- package/dist/capabilities/links.js +1 -1
- package/dist/http/AgreementClient.d.ts +9 -12
- package/dist/http/AgreementClient.js +3 -66
- package/dist/http/ChatClient.d.ts +13 -2
- package/dist/http/ChatClient.js +14 -4
- package/dist/http/ContextGrantsClient.d.ts +10 -4
- package/dist/http/IntroductionsClient.d.ts +60 -0
- package/dist/http/IntroductionsClient.js +54 -0
- package/dist/http/MarketplaceClient.d.ts +0 -16
- package/dist/http/MarketplaceClient.js +0 -17
- package/dist/http/TaskClient.d.ts +40 -1
- package/dist/http/TaskClient.js +51 -2
- package/dist/http/grants.d.ts +9 -3
- package/dist/http/grants.js +14 -1
- package/dist/http/index.d.ts +2 -0
- package/dist/http/index.js +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/types.d.ts +29 -0
- package/package.json +1 -1
- package/dist/relay/provisionRelayWorkers.d.ts +0 -53
- package/dist/relay/provisionRelayWorkers.js +0 -147
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { claimOpenAgreement, delegateAgreement, getMyAgreements, pullOffers, } from '../http/index.js';
|
|
2
|
-
function providerAgentId(agreement) {
|
|
3
|
-
return agreement.parties?.provider?.actor ?? null;
|
|
4
|
-
}
|
|
5
|
-
function isActiveAgreement(agreement) {
|
|
6
|
-
return agreement.status === 'active';
|
|
7
|
-
}
|
|
8
|
-
export function findExistingWorkerDelegation(hireAgreementId, assigneeId, agreements) {
|
|
9
|
-
const matches = agreements.filter((a) => {
|
|
10
|
-
if (a.parentAgreementId !== hireAgreementId)
|
|
11
|
-
return false;
|
|
12
|
-
if (!isActiveAgreement(a))
|
|
13
|
-
return false;
|
|
14
|
-
return providerAgentId(a) === assigneeId;
|
|
15
|
-
});
|
|
16
|
-
matches.sort((a, b) => {
|
|
17
|
-
const ta = a.updatedAt ?? a.createdAt ?? '';
|
|
18
|
-
const tb = b.updatedAt ?? b.createdAt ?? '';
|
|
19
|
-
return tb.localeCompare(ta);
|
|
20
|
-
});
|
|
21
|
-
return matches[0] ?? null;
|
|
22
|
-
}
|
|
23
|
-
export function findOpenOfferForAgent(assigneeId, offers) {
|
|
24
|
-
return (offers.find((o) => {
|
|
25
|
-
if (o.status !== 'open' && o.status !== 'active')
|
|
26
|
-
return false;
|
|
27
|
-
return providerAgentId(o) === assigneeId;
|
|
28
|
-
}) ?? null);
|
|
29
|
-
}
|
|
30
|
-
export async function provisionRelayWorkers(input, deps = {
|
|
31
|
-
getMyAgreements,
|
|
32
|
-
pullOffers,
|
|
33
|
-
claimOpenAgreement,
|
|
34
|
-
delegateAgreement,
|
|
35
|
-
}) {
|
|
36
|
-
const { creds, hireAgreementId, chatId, steps, inputArtifactIds } = input;
|
|
37
|
-
if (!steps.length)
|
|
38
|
-
throw new Error('steps must not be empty');
|
|
39
|
-
const myAgreements = (await deps.getMyAgreements({}, creds));
|
|
40
|
-
let offersCache = null;
|
|
41
|
-
const provisioned = [];
|
|
42
|
-
const pendingApprovals = [];
|
|
43
|
-
for (const step of steps) {
|
|
44
|
-
const existing = findExistingWorkerDelegation(hireAgreementId, step.assigneeId, myAgreements);
|
|
45
|
-
if (existing?.agreementId) {
|
|
46
|
-
provisioned.push({
|
|
47
|
-
stepId: step.stepId,
|
|
48
|
-
order: step.order,
|
|
49
|
-
agreementId: existing.agreementId,
|
|
50
|
-
assigneeId: step.assigneeId,
|
|
51
|
-
description: step.description,
|
|
52
|
-
provisionMethod: 'existing',
|
|
53
|
-
status: 'active',
|
|
54
|
-
});
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
if (step.offerAgreementId) {
|
|
58
|
-
const { agreement: claimed } = await deps.claimOpenAgreement(step.offerAgreementId, creds);
|
|
59
|
-
const agreementId = claimed.agreementId;
|
|
60
|
-
const status = isActiveAgreement(claimed)
|
|
61
|
-
? 'active'
|
|
62
|
-
: 'pending_approval';
|
|
63
|
-
if (status === 'pending_approval')
|
|
64
|
-
pendingApprovals.push(agreementId);
|
|
65
|
-
provisioned.push({
|
|
66
|
-
stepId: step.stepId,
|
|
67
|
-
order: step.order,
|
|
68
|
-
agreementId,
|
|
69
|
-
assigneeId: step.assigneeId,
|
|
70
|
-
description: step.description,
|
|
71
|
-
provisionMethod: 'claim',
|
|
72
|
-
status,
|
|
73
|
-
});
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
if (!offersCache) {
|
|
77
|
-
offersCache = await deps.pullOffers({ limit: 100 }, creds);
|
|
78
|
-
}
|
|
79
|
-
const openOffer = findOpenOfferForAgent(step.assigneeId, offersCache);
|
|
80
|
-
if (openOffer?.agreementId) {
|
|
81
|
-
const { agreement: claimed } = await deps.claimOpenAgreement(openOffer.agreementId, creds);
|
|
82
|
-
const agreementId = claimed.agreementId;
|
|
83
|
-
const status = isActiveAgreement(claimed)
|
|
84
|
-
? 'active'
|
|
85
|
-
: 'pending_approval';
|
|
86
|
-
if (status === 'pending_approval')
|
|
87
|
-
pendingApprovals.push(agreementId);
|
|
88
|
-
provisioned.push({
|
|
89
|
-
stepId: step.stepId,
|
|
90
|
-
order: step.order,
|
|
91
|
-
agreementId,
|
|
92
|
-
assigneeId: step.assigneeId,
|
|
93
|
-
description: step.description,
|
|
94
|
-
provisionMethod: 'claim',
|
|
95
|
-
status,
|
|
96
|
-
});
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
if (!chatId?.trim()) {
|
|
100
|
-
throw new Error(`No standing offer found for ${step.assigneeId} and chatId is required to propose a delegation under the hire`);
|
|
101
|
-
}
|
|
102
|
-
const delegated = await deps.delegateAgreement({
|
|
103
|
-
description: step.description,
|
|
104
|
-
executorId: step.assigneeId,
|
|
105
|
-
chatId: chatId.trim(),
|
|
106
|
-
parentAgreementId: hireAgreementId,
|
|
107
|
-
agreementDescription: `Relay step ${step.stepId}: ${step.description}`,
|
|
108
|
-
lifecycle: 'count-bound',
|
|
109
|
-
maxExecutions: 50,
|
|
110
|
-
price: 0,
|
|
111
|
-
}, creds);
|
|
112
|
-
const agreementId = delegated.agreementId;
|
|
113
|
-
const status = isActiveAgreement(delegated)
|
|
114
|
-
? 'active'
|
|
115
|
-
: 'pending_approval';
|
|
116
|
-
if (status === 'pending_approval')
|
|
117
|
-
pendingApprovals.push(agreementId);
|
|
118
|
-
provisioned.push({
|
|
119
|
-
stepId: step.stepId,
|
|
120
|
-
order: step.order,
|
|
121
|
-
agreementId,
|
|
122
|
-
assigneeId: step.assigneeId,
|
|
123
|
-
description: step.description,
|
|
124
|
-
provisionMethod: 'delegate',
|
|
125
|
-
status,
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
provisioned.sort((a, b) => a.order - b.order);
|
|
129
|
-
const payload = {
|
|
130
|
-
inputArtifactIds,
|
|
131
|
-
steps: provisioned.map(({ stepId, order, agreementId, assigneeId, description }) => ({
|
|
132
|
-
stepId,
|
|
133
|
-
order,
|
|
134
|
-
agreementId,
|
|
135
|
-
assigneeId,
|
|
136
|
-
description,
|
|
137
|
-
})),
|
|
138
|
-
};
|
|
139
|
-
const readyForKickoff = pendingApprovals.length === 0 &&
|
|
140
|
-
provisioned.every((s) => s.status === 'active');
|
|
141
|
-
return {
|
|
142
|
-
payload,
|
|
143
|
-
steps: provisioned,
|
|
144
|
-
pendingApprovals,
|
|
145
|
-
readyForKickoff,
|
|
146
|
-
};
|
|
147
|
-
}
|