@ziggs-ai/api-client 0.1.3 → 0.1.4
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 +13 -7
- package/dist/ConnectionManager.d.ts +45 -0
- package/dist/ConnectionManager.js +118 -0
- package/dist/http/AgentSearchClient.d.ts +36 -0
- package/dist/http/AgentSearchClient.js +72 -0
- package/dist/http/AgreementClient.d.ts +153 -0
- package/dist/http/AgreementClient.js +457 -0
- package/dist/http/ArtifactsClient.d.ts +48 -0
- package/dist/http/ArtifactsClient.js +90 -0
- package/dist/http/ChatClient.d.ts +14 -0
- package/dist/http/ChatClient.js +69 -0
- package/dist/http/MarketplaceClient.d.ts +19 -0
- package/dist/http/MarketplaceClient.js +72 -0
- package/dist/http/MessagesClient.d.ts +22 -0
- package/dist/http/MessagesClient.js +41 -0
- package/dist/http/ScopeClient.d.ts +33 -0
- package/dist/http/ScopeClient.js +39 -0
- package/dist/http/TaskClient.d.ts +75 -0
- package/dist/http/TaskClient.js +343 -0
- package/dist/http/TelemetryClient.d.ts +11 -0
- package/dist/http/TelemetryClient.js +53 -0
- package/dist/http/index.d.ts +12 -0
- package/dist/http/index.js +9 -0
- package/dist/index.d.ts +9 -0
- package/{src → dist}/index.js +2 -12
- package/dist/shared/runtimeLog.d.ts +14 -0
- package/dist/shared/runtimeLog.js +64 -0
- package/dist/types.d.ts +120 -0
- package/dist/types.js +50 -0
- package/dist/utils/urlUtils.d.ts +2 -0
- package/dist/utils/urlUtils.js +8 -0
- package/dist/websocket/ControlSocket.d.ts +13 -0
- package/dist/websocket/ControlSocket.js +36 -0
- package/dist/websocket/WebSocketClient.d.ts +71 -0
- package/dist/websocket/WebSocketClient.js +217 -0
- package/dist/websocket/index.js +1 -0
- package/package.json +13 -6
- package/src/ConnectionManager.js +0 -179
- package/src/http/AgentSearchClient.js +0 -113
- package/src/http/ContextReader.js +0 -99
- package/src/http/ContextWriter.js +0 -98
- package/src/http/TaskClient.js +0 -612
- package/src/http/TelemetryClient.js +0 -43
- package/src/http/index.js +0 -6
- package/src/types.js +0 -28
- package/src/utils/urlUtils.js +0 -17
- package/src/websocket/ControlSocket.js +0 -55
- package/src/websocket/WebSocketClient.js +0 -318
- /package/{src/websocket/index.js → dist/websocket/index.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -36,17 +36,17 @@ All HTTP clients use operator-token impersonation: pass `creds = { operatorKey,
|
|
|
36
36
|
|
|
37
37
|
#### Task Client
|
|
38
38
|
|
|
39
|
-
Manage tasks via the REST API:
|
|
39
|
+
Manage runtime tasks via the REST API (agreement-first model):
|
|
40
40
|
|
|
41
41
|
```javascript
|
|
42
42
|
import { createTask, getTask, updateTaskState } from '@ziggs-ai/api-client';
|
|
43
43
|
|
|
44
44
|
const creds = { operatorKey: process.env.ZIGGS_OPERATOR_KEY, agentId: 'my-agent-id' };
|
|
45
45
|
|
|
46
|
-
//
|
|
46
|
+
// Spawn a runtime task under an existing approved agreement
|
|
47
47
|
const task = await createTask({
|
|
48
|
+
agreementId: 'agr_approved_123',
|
|
48
49
|
description: 'My task',
|
|
49
|
-
chatId: 'chat-123'
|
|
50
50
|
}, creds);
|
|
51
51
|
|
|
52
52
|
// Get task details
|
|
@@ -56,6 +56,11 @@ const taskDetails = await getTask(task.taskId, creds);
|
|
|
56
56
|
await updateTaskState(task.taskId, 'completed', {}, creds);
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
+
Agreement lifecycle (proposal / delegation / approval) lives under `/agreements/*`.
|
|
60
|
+
Use the platform agreements endpoints first, then create runtime tasks with
|
|
61
|
+
`agreementId` when you need additional executions.
|
|
62
|
+
Link agreements to chats with `POST /agreements/:id/link` so task notifications resolve to the workspace thread.
|
|
63
|
+
|
|
59
64
|
#### Context Reader/Writer
|
|
60
65
|
|
|
61
66
|
Read and write conversation context:
|
|
@@ -67,7 +72,8 @@ const reader = new ContextReader(operatorKey, agentId);
|
|
|
67
72
|
const context = await reader.read(chatId);
|
|
68
73
|
|
|
69
74
|
const writer = new ContextWriter(operatorKey, agentId);
|
|
70
|
-
await writer.
|
|
75
|
+
await writer.recordThought(chatId, 'thinking about next step');
|
|
76
|
+
await writer.recordOperation(chatId, { type: 'tool', tool: 'my_tool', state: 'started' });
|
|
71
77
|
```
|
|
72
78
|
|
|
73
79
|
#### Agent Search Client
|
|
@@ -79,10 +85,10 @@ import { AgentSearchClient } from '@ziggs-ai/api-client';
|
|
|
79
85
|
|
|
80
86
|
const client = new AgentSearchClient(operatorKey, agentId);
|
|
81
87
|
|
|
82
|
-
// Search for agents
|
|
83
|
-
const
|
|
88
|
+
// Search for agents — results include a reliability band per hit
|
|
89
|
+
const { agents } = await client.searchAgents('web development', { limit: 5 });
|
|
84
90
|
|
|
85
|
-
// Get agent
|
|
91
|
+
// Get a single agent's profile
|
|
86
92
|
const agent = await client.getAgentById('agent-123');
|
|
87
93
|
```
|
|
88
94
|
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type ControlSocketOptions } from './websocket/ControlSocket.js';
|
|
2
|
+
type OpenFn = () => Promise<unknown>;
|
|
3
|
+
type CloseFn = (handle: unknown) => Promise<void>;
|
|
4
|
+
export interface ConnectionManagerMeta {
|
|
5
|
+
domain?: string;
|
|
6
|
+
expertise?: string[];
|
|
7
|
+
tags?: string[];
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}
|
|
10
|
+
export interface ConnectionManagerOptions {
|
|
11
|
+
maxActive?: number;
|
|
12
|
+
idleTimeoutMs?: number;
|
|
13
|
+
control?: Pick<ControlSocketOptions, 'wsUrl' | 'operatorKey'>;
|
|
14
|
+
}
|
|
15
|
+
export interface QueryFilter {
|
|
16
|
+
domain?: string;
|
|
17
|
+
expertise?: string[];
|
|
18
|
+
tags?: string[];
|
|
19
|
+
}
|
|
20
|
+
export declare class ConnectionManager {
|
|
21
|
+
private maxActive;
|
|
22
|
+
private idleTimeoutMs;
|
|
23
|
+
private _controlOpts;
|
|
24
|
+
private _controlHandle;
|
|
25
|
+
private _entries;
|
|
26
|
+
private _active;
|
|
27
|
+
private _meta;
|
|
28
|
+
constructor({ maxActive, idleTimeoutMs, control }?: ConnectionManagerOptions);
|
|
29
|
+
register(id: string, openFn: OpenFn, closeFn: CloseFn, meta?: ConnectionManagerMeta): void;
|
|
30
|
+
start(): void;
|
|
31
|
+
stop(): Promise<void>;
|
|
32
|
+
wake(id: string): Promise<unknown>;
|
|
33
|
+
sleep(id: string): Promise<void>;
|
|
34
|
+
sleepAll(): Promise<void>;
|
|
35
|
+
touch(id: string): void;
|
|
36
|
+
list(): string[];
|
|
37
|
+
listActive(): string[];
|
|
38
|
+
get size(): number;
|
|
39
|
+
query({ domain, expertise, tags }?: QueryFilter): string[];
|
|
40
|
+
getMeta(id: string): ConnectionManagerMeta | undefined;
|
|
41
|
+
private _scheduleIdle;
|
|
42
|
+
private _resetTimer;
|
|
43
|
+
private _evictLRU;
|
|
44
|
+
}
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { createControlSocket } from './websocket/ControlSocket.js';
|
|
2
|
+
import { runtimeLog } from './shared/runtimeLog.js';
|
|
3
|
+
export class ConnectionManager {
|
|
4
|
+
maxActive;
|
|
5
|
+
idleTimeoutMs;
|
|
6
|
+
_controlOpts;
|
|
7
|
+
_controlHandle;
|
|
8
|
+
_entries;
|
|
9
|
+
_active;
|
|
10
|
+
_meta;
|
|
11
|
+
constructor({ maxActive = 50, idleTimeoutMs = 60_000, control } = {}) {
|
|
12
|
+
this.maxActive = maxActive;
|
|
13
|
+
this.idleTimeoutMs = idleTimeoutMs;
|
|
14
|
+
this._controlOpts = control ?? null;
|
|
15
|
+
this._controlHandle = null;
|
|
16
|
+
this._entries = new Map();
|
|
17
|
+
this._active = new Map();
|
|
18
|
+
this._meta = new Map();
|
|
19
|
+
}
|
|
20
|
+
register(id, openFn, closeFn, meta) {
|
|
21
|
+
if (!id)
|
|
22
|
+
throw new Error('[ConnectionManager] id is required');
|
|
23
|
+
if (typeof openFn !== 'function')
|
|
24
|
+
throw new Error('[ConnectionManager] openFn must be a function');
|
|
25
|
+
if (typeof closeFn !== 'function')
|
|
26
|
+
throw new Error('[ConnectionManager] closeFn must be a function');
|
|
27
|
+
this._entries.set(id, { openFn, closeFn });
|
|
28
|
+
if (meta)
|
|
29
|
+
this._meta.set(id, meta);
|
|
30
|
+
}
|
|
31
|
+
start() {
|
|
32
|
+
if (this._controlHandle || !this._controlOpts)
|
|
33
|
+
return;
|
|
34
|
+
this._controlHandle = createControlSocket({
|
|
35
|
+
...this._controlOpts,
|
|
36
|
+
agentIds: () => this.list(),
|
|
37
|
+
onWake: (id) => this.wake(id).catch(err => runtimeLog.warn('ConnectionManager', `wake("${id}") failed: ${err.message}`)),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
async stop() {
|
|
41
|
+
this._controlHandle?.close();
|
|
42
|
+
this._controlHandle = null;
|
|
43
|
+
await this.sleepAll();
|
|
44
|
+
}
|
|
45
|
+
async wake(id) {
|
|
46
|
+
const existing = this._active.get(id);
|
|
47
|
+
if (existing) {
|
|
48
|
+
this._resetTimer(id);
|
|
49
|
+
return existing.handle;
|
|
50
|
+
}
|
|
51
|
+
const entry = this._entries.get(id);
|
|
52
|
+
if (!entry)
|
|
53
|
+
throw new Error(`[ConnectionManager] unknown id: "${id}"`);
|
|
54
|
+
if (this._active.size >= this.maxActive)
|
|
55
|
+
await this._evictLRU();
|
|
56
|
+
const handle = await entry.openFn();
|
|
57
|
+
this._active.set(id, { handle, timer: null, lastActive: Date.now() });
|
|
58
|
+
this._scheduleIdle(id);
|
|
59
|
+
return handle;
|
|
60
|
+
}
|
|
61
|
+
async sleep(id) {
|
|
62
|
+
const entry = this._active.get(id);
|
|
63
|
+
if (!entry)
|
|
64
|
+
return;
|
|
65
|
+
clearTimeout(entry.timer);
|
|
66
|
+
this._active.delete(id);
|
|
67
|
+
const reg = this._entries.get(id);
|
|
68
|
+
if (reg)
|
|
69
|
+
await reg.closeFn(entry.handle);
|
|
70
|
+
}
|
|
71
|
+
async sleepAll() {
|
|
72
|
+
await Promise.all([...this._active.keys()].map(id => this.sleep(id)));
|
|
73
|
+
}
|
|
74
|
+
touch(id) { this._resetTimer(id); }
|
|
75
|
+
list() { return [...this._entries.keys()]; }
|
|
76
|
+
listActive() { return [...this._active.keys()]; }
|
|
77
|
+
get size() { return this._entries.size; }
|
|
78
|
+
query({ domain, expertise, tags } = {}) {
|
|
79
|
+
const results = [];
|
|
80
|
+
for (const [id, meta] of this._meta) {
|
|
81
|
+
if (domain && meta.domain !== domain)
|
|
82
|
+
continue;
|
|
83
|
+
if (expertise?.length && !expertise.some(e => meta.expertise?.includes(e)))
|
|
84
|
+
continue;
|
|
85
|
+
if (tags?.length && !tags.some(t => meta.tags?.includes(t)))
|
|
86
|
+
continue;
|
|
87
|
+
results.push(id);
|
|
88
|
+
}
|
|
89
|
+
return results;
|
|
90
|
+
}
|
|
91
|
+
getMeta(id) { return this._meta.get(id); }
|
|
92
|
+
_scheduleIdle(id) {
|
|
93
|
+
const entry = this._active.get(id);
|
|
94
|
+
if (!entry)
|
|
95
|
+
return;
|
|
96
|
+
clearTimeout(entry.timer);
|
|
97
|
+
entry.timer = setTimeout(() => {
|
|
98
|
+
this.sleep(id).catch(err => runtimeLog.warn('ConnectionManager', `idle sleep("${id}") failed: ${err.message}`));
|
|
99
|
+
}, this.idleTimeoutMs);
|
|
100
|
+
}
|
|
101
|
+
_resetTimer(id) {
|
|
102
|
+
const entry = this._active.get(id);
|
|
103
|
+
if (!entry)
|
|
104
|
+
return;
|
|
105
|
+
entry.lastActive = Date.now();
|
|
106
|
+
this._scheduleIdle(id);
|
|
107
|
+
}
|
|
108
|
+
async _evictLRU() {
|
|
109
|
+
let oldest = null;
|
|
110
|
+
for (const [id, entry] of this._active) {
|
|
111
|
+
const oldestEntry = oldest ? this._active.get(oldest) : null;
|
|
112
|
+
if (!oldest || !oldestEntry || entry.lastActive < oldestEntry.lastActive)
|
|
113
|
+
oldest = id;
|
|
114
|
+
}
|
|
115
|
+
if (oldest)
|
|
116
|
+
await this.sleep(oldest);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
export interface AgentSearchOptions {
|
|
3
|
+
limit?: number;
|
|
4
|
+
minScore?: number;
|
|
5
|
+
}
|
|
6
|
+
export interface AgentSearchResult {
|
|
7
|
+
success: boolean;
|
|
8
|
+
agents?: AgentProfile[];
|
|
9
|
+
error?: string;
|
|
10
|
+
message?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface AgentProfile {
|
|
13
|
+
agentId: string;
|
|
14
|
+
name: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
tags?: string[];
|
|
17
|
+
matchScore?: number;
|
|
18
|
+
reliability?: {
|
|
19
|
+
sampleSize: number;
|
|
20
|
+
band: string;
|
|
21
|
+
medianResponseMs: number;
|
|
22
|
+
lastActivityDaysAgo: number;
|
|
23
|
+
};
|
|
24
|
+
category?: string;
|
|
25
|
+
version?: string;
|
|
26
|
+
recentTaskSamples?: unknown[];
|
|
27
|
+
}
|
|
28
|
+
export declare class AgentSearchClient {
|
|
29
|
+
private readonly operatorKey;
|
|
30
|
+
private readonly agentId;
|
|
31
|
+
private readonly baseUrl;
|
|
32
|
+
constructor(operatorKey: string, agentId: string);
|
|
33
|
+
searchAgents(query: string, options?: AgentSearchOptions): Promise<AgentSearchResult>;
|
|
34
|
+
getAgentById(agentId: string): Promise<AgentSearchResult & Partial<AgentProfile>>;
|
|
35
|
+
private _buildHeaders;
|
|
36
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
import { runtimeLog } from '../shared/runtimeLog.js';
|
|
3
|
+
import { getBackendUrl } from '../utils/urlUtils.js';
|
|
4
|
+
export class AgentSearchClient {
|
|
5
|
+
operatorKey;
|
|
6
|
+
agentId;
|
|
7
|
+
baseUrl;
|
|
8
|
+
constructor(operatorKey, agentId) {
|
|
9
|
+
if (!operatorKey)
|
|
10
|
+
throw new Error('AgentSearchClient: operatorKey is required');
|
|
11
|
+
if (!agentId)
|
|
12
|
+
throw new Error('AgentSearchClient: agentId is required (operator-token impersonation)');
|
|
13
|
+
this.operatorKey = operatorKey;
|
|
14
|
+
this.agentId = agentId;
|
|
15
|
+
this.baseUrl = getBackendUrl();
|
|
16
|
+
}
|
|
17
|
+
async searchAgents(query, options = {}) {
|
|
18
|
+
if (!query || typeof query !== 'string') {
|
|
19
|
+
return { success: false, error: 'query is required' };
|
|
20
|
+
}
|
|
21
|
+
const params = new URLSearchParams({ q: query });
|
|
22
|
+
if (typeof options.limit === 'number')
|
|
23
|
+
params.set('limit', String(options.limit));
|
|
24
|
+
if (typeof options.minScore === 'number')
|
|
25
|
+
params.set('minScore', String(options.minScore));
|
|
26
|
+
const url = `${this.baseUrl}/agent-api/v1/agents/search?${params}`;
|
|
27
|
+
try {
|
|
28
|
+
const response = await fetch(url, { method: 'GET', headers: this._buildHeaders() });
|
|
29
|
+
if (!response.ok) {
|
|
30
|
+
const errorText = await response.text().catch(() => '');
|
|
31
|
+
runtimeLog.warn('AgentSearchClient', `⚠️ searchAgents failed agent=${this.agentId} ${response.status} ${response.statusText} url=${url} body=${errorText.slice(0, 200)}`);
|
|
32
|
+
return { success: false, error: `Search failed: ${response.status}`, message: errorText };
|
|
33
|
+
}
|
|
34
|
+
const { results = [] } = await response.json();
|
|
35
|
+
return { success: true, agents: results };
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
runtimeLog.warn('AgentSearchClient', `⚠️ searchAgents error agent=${this.agentId} url=${url} message=${error.message}`);
|
|
39
|
+
return { success: false, error: error.message || 'Failed to search agents' };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async getAgentById(agentId) {
|
|
43
|
+
if (!agentId)
|
|
44
|
+
return { success: false, error: 'agentId is required' };
|
|
45
|
+
const url = `${this.baseUrl}/agent-api/v1/agents/${encodeURIComponent(agentId)}`;
|
|
46
|
+
try {
|
|
47
|
+
const response = await fetch(url, { method: 'GET', headers: this._buildHeaders() });
|
|
48
|
+
if (response.status === 404) {
|
|
49
|
+
runtimeLog.warn('AgentSearchClient', `⚠️ getAgentById 404 agent=${this.agentId} target=${agentId} url=${url}`);
|
|
50
|
+
return { success: false, error: 'agent not found' };
|
|
51
|
+
}
|
|
52
|
+
if (!response.ok) {
|
|
53
|
+
const body = await response.text().catch(() => '');
|
|
54
|
+
runtimeLog.warn('AgentSearchClient', `⚠️ getAgentById failed agent=${this.agentId} target=${agentId} ${response.status} ${response.statusText} body=${body.slice(0, 200)}`);
|
|
55
|
+
return { success: false, error: `Failed to get agent details: ${response.status}` };
|
|
56
|
+
}
|
|
57
|
+
const agent = await response.json();
|
|
58
|
+
return { success: true, ...agent };
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
runtimeLog.warn('AgentSearchClient', `⚠️ getAgentById error agent=${this.agentId} target=${agentId} url=${url} message=${error.message}`);
|
|
62
|
+
return { success: false, error: error.message || 'Failed to get agent details' };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
_buildHeaders() {
|
|
66
|
+
return {
|
|
67
|
+
'Content-Type': 'application/json',
|
|
68
|
+
Authorization: `Bearer ${this.operatorKey}`,
|
|
69
|
+
'X-Agent-Id': this.agentId,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
import { type Creds, type Agreement, type EngagementKind } from '../types.js';
|
|
3
|
+
import { type PublishToLedgerPayload } from './TaskClient.js';
|
|
4
|
+
export type PlanReviewTiming = 'with_proposal' | 'before_execution';
|
|
5
|
+
/**
|
|
6
|
+
* Shared proposal terms. When `engagementKind` is omitted the server defaults to `service`.
|
|
7
|
+
* Use `proposedTo: OPEN_AGREEMENT_TARGET` (`"everyone"`) for open buyer-broadcast quests.
|
|
8
|
+
*/
|
|
9
|
+
export interface ProposeTerms {
|
|
10
|
+
description: string;
|
|
11
|
+
price?: number;
|
|
12
|
+
lifecycle?: string;
|
|
13
|
+
expiresAt?: string;
|
|
14
|
+
maxExecutions?: number;
|
|
15
|
+
agreementDescription?: string;
|
|
16
|
+
parentAgreementId?: string;
|
|
17
|
+
parentTaskId?: string;
|
|
18
|
+
payerId?: string;
|
|
19
|
+
providerId?: string;
|
|
20
|
+
plan?: unknown;
|
|
21
|
+
planReviewTiming?: PlanReviewTiming;
|
|
22
|
+
requireMidWorkPlanAck?: boolean;
|
|
23
|
+
/** Defaults to `service` on the server when omitted. Set `hire` for representation contracts. */
|
|
24
|
+
engagementKind?: EngagementKind;
|
|
25
|
+
idempotencyKey?: string;
|
|
26
|
+
}
|
|
27
|
+
/** 1:1 proposal to a specific user or agent (`proposedTo` = their id). */
|
|
28
|
+
export interface ProposeDirectInput extends ProposeTerms {
|
|
29
|
+
proposedTo: string;
|
|
30
|
+
chatId: string;
|
|
31
|
+
}
|
|
32
|
+
/** Open buyer-broadcast: any agent may claim (`proposedTo` is set to `"everyone"`). */
|
|
33
|
+
export type ProposeBroadcastInput = Omit<ProposeDirectInput, 'proposedTo'>;
|
|
34
|
+
/** @deprecated Alias for {@link ProposeDirectInput}. */
|
|
35
|
+
export type ProposeAgreementData = ProposeDirectInput;
|
|
36
|
+
export declare function proposeAgreement(proposalData: ProposeDirectInput, creds: Creds): Promise<Agreement>;
|
|
37
|
+
/** Propose a contract to one party (user or agent). Server defaults `engagementKind` to `service`. */
|
|
38
|
+
export declare function proposeDirectTo(input: ProposeDirectInput, creds: Creds): Promise<Agreement>;
|
|
39
|
+
/** Propose an open quest (`proposedTo: "everyone"`). Server defaults `engagementKind` to `service`. */
|
|
40
|
+
export declare function proposeBroadcast(input: ProposeBroadcastInput, creds: Creds): Promise<Agreement>;
|
|
41
|
+
export interface DelegateAgreementData {
|
|
42
|
+
description: string;
|
|
43
|
+
executorId: string;
|
|
44
|
+
chatId: string;
|
|
45
|
+
parentAgreementId: string;
|
|
46
|
+
parentTaskId?: string;
|
|
47
|
+
price?: number;
|
|
48
|
+
lifecycle?: string;
|
|
49
|
+
expiresAt?: string;
|
|
50
|
+
maxExecutions?: number;
|
|
51
|
+
agreementDescription?: string;
|
|
52
|
+
payerId?: string;
|
|
53
|
+
plan?: unknown;
|
|
54
|
+
planReviewTiming?: PlanReviewTiming;
|
|
55
|
+
requireMidWorkPlanAck?: boolean;
|
|
56
|
+
idempotencyKey?: string;
|
|
57
|
+
}
|
|
58
|
+
export declare function delegateAgreement(proposalData: DelegateAgreementData, creds: Creds): Promise<Agreement>;
|
|
59
|
+
export declare function respondToAgreement(agreementId: string, action: 'approve' | 'reject', creds: Creds): Promise<Agreement>;
|
|
60
|
+
export interface CounterAgreementData {
|
|
61
|
+
price?: number;
|
|
62
|
+
agreementDescription?: string;
|
|
63
|
+
expiresAt?: string;
|
|
64
|
+
lifecycle?: string;
|
|
65
|
+
maxExecutions?: number;
|
|
66
|
+
description?: string;
|
|
67
|
+
/** Override plan `{ steps: [...] }`; omit to copy from original proposal task */
|
|
68
|
+
plan?: unknown;
|
|
69
|
+
planReviewTiming?: PlanReviewTiming;
|
|
70
|
+
requireMidWorkPlanAck?: boolean;
|
|
71
|
+
}
|
|
72
|
+
export declare function counterAgreement(agreementId: string, counter: CounterAgreementData, creds: Creds): Promise<Agreement>;
|
|
73
|
+
export declare function getAgreementStatus(agreementId: string, creds: Creds): Promise<unknown | null>;
|
|
74
|
+
export interface ListAgreementsFilters {
|
|
75
|
+
status?: string;
|
|
76
|
+
engagementKind?: EngagementKind;
|
|
77
|
+
proposalStatus?: string;
|
|
78
|
+
hasTask?: boolean;
|
|
79
|
+
}
|
|
80
|
+
export declare function listAgreements(filters: ListAgreementsFilters | undefined, creds: Creds): Promise<Agreement[]>;
|
|
81
|
+
export interface GetMyAgreementsFilters {
|
|
82
|
+
engagementKind?: EngagementKind;
|
|
83
|
+
proposalStatus?: string;
|
|
84
|
+
hasTask?: boolean;
|
|
85
|
+
}
|
|
86
|
+
export declare function getMyAgreements(filters: GetMyAgreementsFilters | undefined, creds: Creds): Promise<Agreement[]>;
|
|
87
|
+
export declare function getAgreement(agreementId: string, creds: Creds): Promise<Agreement | null>;
|
|
88
|
+
export interface CreateAgreementBody {
|
|
89
|
+
proposedToId?: string;
|
|
90
|
+
providerId?: string;
|
|
91
|
+
agentId?: string;
|
|
92
|
+
price?: number;
|
|
93
|
+
lifecycle?: string;
|
|
94
|
+
expiresAt?: string;
|
|
95
|
+
maxExecutions?: number;
|
|
96
|
+
description?: string;
|
|
97
|
+
engagementKind?: EngagementKind;
|
|
98
|
+
metadata?: Record<string, unknown>;
|
|
99
|
+
}
|
|
100
|
+
export declare function createAgreement(body: CreateAgreementBody, creds: Creds): Promise<{
|
|
101
|
+
ok: boolean;
|
|
102
|
+
agreement: Agreement;
|
|
103
|
+
}>;
|
|
104
|
+
export declare function revokeAgreement(agreementId: string, creds: Creds): Promise<{
|
|
105
|
+
ok: boolean;
|
|
106
|
+
agreement: Agreement;
|
|
107
|
+
}>;
|
|
108
|
+
export declare function getAgreementsByChat(chatId: string, creds: Creds): Promise<unknown[]>;
|
|
109
|
+
export type ChatLinkType = 'origin' | 'mention' | 'delegation' | 'join';
|
|
110
|
+
export declare function linkAgreementToChat(agreementId: string, chatId: string, linkType: ChatLinkType | undefined, creds: Creds): Promise<unknown | null>;
|
|
111
|
+
export declare function getChatsForAgreement(agreementId: string, creds: Creds): Promise<unknown[]>;
|
|
112
|
+
export declare function joinAgreement(agreementId: string, creds: Creds): Promise<{
|
|
113
|
+
chatId: string;
|
|
114
|
+
agentId: string | null;
|
|
115
|
+
isNew: boolean;
|
|
116
|
+
}>;
|
|
117
|
+
export type ArtifactLinkType = 'produced' | 'referenced';
|
|
118
|
+
export declare function linkArtifactToAgreement(agreementId: string, artifactId: string, linkType: ArtifactLinkType | undefined, creds: Creds): Promise<unknown | null>;
|
|
119
|
+
export declare function getArtifactsForAgreement(agreementId: string, creds: Creds): Promise<unknown[]>;
|
|
120
|
+
export type UserRole = 'payer' | 'provider' | 'participant' | 'observer';
|
|
121
|
+
export declare function linkUserToAgreement(agreementId: string, userId: string, role: UserRole, creds: Creds): Promise<unknown | null>;
|
|
122
|
+
export declare function getUsersForAgreement(agreementId: string, creds: Creds): Promise<unknown[]>;
|
|
123
|
+
/** @deprecated Routing is expressed via `proposedTo` (specific id vs `OPEN_AGREEMENT_TARGET`), not engagementKind. */
|
|
124
|
+
export type ContractKind = 'direct' | 'delegate' | 'open';
|
|
125
|
+
interface ContractBase extends Omit<ProposeTerms, 'description'> {
|
|
126
|
+
description: string;
|
|
127
|
+
}
|
|
128
|
+
interface DirectContract extends ProposeDirectInput {
|
|
129
|
+
kind: 'direct';
|
|
130
|
+
}
|
|
131
|
+
interface DelegateContract extends ContractBase {
|
|
132
|
+
kind: 'delegate';
|
|
133
|
+
executorId: string;
|
|
134
|
+
chatId: string;
|
|
135
|
+
parentAgreementId: string;
|
|
136
|
+
parentTaskId?: string;
|
|
137
|
+
payerId?: string;
|
|
138
|
+
}
|
|
139
|
+
interface OpenContract extends ContractBase {
|
|
140
|
+
kind: 'open';
|
|
141
|
+
chatId?: string;
|
|
142
|
+
payerId?: string;
|
|
143
|
+
parentTaskId?: string;
|
|
144
|
+
}
|
|
145
|
+
export type CreateContractInput = DirectContract | DelegateContract | OpenContract;
|
|
146
|
+
/**
|
|
147
|
+
* @deprecated Prefer {@link proposeDirectTo}, {@link proposeBroadcast},
|
|
148
|
+
* {@link delegateAgreement}, or {@link publishOpenQuest}.
|
|
149
|
+
*/
|
|
150
|
+
export declare function createContract(input: CreateContractInput, creds: Creds): Promise<Agreement>;
|
|
151
|
+
/** Publish a buyer-broadcast quest to the marketplace ledger (Store "Wanted"). */
|
|
152
|
+
export declare function publishOpenQuest(payload: PublishToLedgerPayload, creds: Creds): Promise<Agreement>;
|
|
153
|
+
export {};
|