@agent-os-sdk/client 0.9.8 → 0.9.10
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/client/AgentOsClient.d.ts +6 -2
- package/dist/client/AgentOsClient.d.ts.map +1 -1
- package/dist/client/AgentOsClient.js +10 -3
- package/dist/client/HttpRequestBuilder.d.ts +1 -0
- package/dist/client/HttpRequestBuilder.d.ts.map +1 -1
- package/dist/client/HttpRequestBuilder.js +6 -2
- package/dist/client/auth.d.ts +4 -0
- package/dist/client/auth.d.ts.map +1 -1
- package/dist/client/raw.d.ts +12 -0
- package/dist/client/raw.d.ts.map +1 -1
- package/dist/client/raw.js +67 -3
- package/dist/generated/openapi.d.ts +115 -186
- package/dist/generated/openapi.d.ts.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/modules/agents.d.ts +30 -0
- package/dist/modules/agents.d.ts.map +1 -1
- package/dist/modules/agents.js +25 -1
- package/dist/modules/builder.d.ts +0 -4
- package/dist/modules/builder.d.ts.map +1 -1
- package/dist/modules/credentials.d.ts +4 -1
- package/dist/modules/credentials.d.ts.map +1 -1
- package/dist/modules/credentials.js +36 -1
- package/dist/modules/datasets.d.ts +80 -0
- package/dist/modules/datasets.d.ts.map +1 -0
- package/dist/modules/datasets.js +91 -0
- package/dist/modules/files.d.ts +34 -13
- package/dist/modules/files.d.ts.map +1 -1
- package/dist/modules/files.js +86 -19
- package/dist/modules/graphs.d.ts +1 -1
- package/dist/modules/graphs.d.ts.map +1 -1
- package/dist/modules/members.d.ts +0 -6
- package/dist/modules/members.d.ts.map +1 -1
- package/dist/modules/members.js +0 -6
- package/dist/modules/observability.d.ts +19 -0
- package/dist/modules/observability.d.ts.map +1 -0
- package/dist/modules/observability.js +14 -0
- package/dist/modules/roles.d.ts +64 -0
- package/dist/modules/roles.d.ts.map +1 -0
- package/dist/modules/roles.js +79 -0
- package/dist/modules/runs.d.ts +2 -0
- package/dist/modules/runs.d.ts.map +1 -1
- package/dist/modules/runs.js +2 -2
- package/dist/modules/threads.js +2 -2
- package/dist/modules/triggers.d.ts +51 -5
- package/dist/modules/triggers.d.ts.map +1 -1
- package/dist/modules/triggers.js +39 -0
- package/dist/modules/usage.d.ts +68 -9
- package/dist/modules/usage.d.ts.map +1 -1
- package/dist/modules/usage.js +27 -3
- package/dist/modules/vectorStores.d.ts +6 -3
- package/dist/modules/vectorStores.d.ts.map +1 -1
- package/dist/modules/vectorStores.js +86 -14
- package/package.json +1 -1
- package/src/client/AgentOsClient.ts +10 -3
- package/src/client/HttpRequestBuilder.ts +7 -2
- package/src/client/auth.ts +4 -0
- package/src/client/raw.ts +91 -4
- package/src/generated/openapi.ts +115 -186
- package/src/generated/swagger.json +96 -180
- package/src/index.ts +4 -1
- package/src/modules/agents.ts +56 -2
- package/src/modules/builder.ts +0 -7
- package/src/modules/credentials.ts +44 -2
- package/src/modules/datasets.ts +142 -0
- package/src/modules/files.ts +125 -29
- package/src/modules/graphs.ts +1 -1
- package/src/modules/members.ts +0 -7
- package/src/modules/observability.ts +28 -0
- package/src/modules/roles.ts +112 -0
- package/src/modules/runs.ts +4 -2
- package/src/modules/threads.ts +2 -2
- package/src/modules/triggers.ts +87 -6
- package/src/modules/usage.ts +94 -9
- package/src/modules/vectorStores.ts +115 -18
- package/src/modules/knowledge.ts +0 -147
package/src/modules/triggers.ts
CHANGED
|
@@ -11,6 +11,9 @@ import type { RawClient, APIResponse } from "../client/raw.js";
|
|
|
11
11
|
// Types - Wave 5 Aligned
|
|
12
12
|
// =============================================================================
|
|
13
13
|
|
|
14
|
+
export type JsonSchema = Record<string, unknown>;
|
|
15
|
+
export type TriggerInputMappingSpec = Record<string, unknown>;
|
|
16
|
+
|
|
14
17
|
export interface Trigger {
|
|
15
18
|
id: string;
|
|
16
19
|
name: string;
|
|
@@ -39,9 +42,19 @@ export interface TriggerRequestContract {
|
|
|
39
42
|
invoke_url: string;
|
|
40
43
|
headers: Record<string, string>;
|
|
41
44
|
signing: SigningContract;
|
|
45
|
+
body_schema_json?: string;
|
|
46
|
+
example_payload_json?: string;
|
|
47
|
+
curl_example: string;
|
|
48
|
+
curl_command_parts?: {
|
|
49
|
+
method: string;
|
|
50
|
+
url: string;
|
|
51
|
+
headers: Record<string, string>;
|
|
52
|
+
body_json?: string | null;
|
|
53
|
+
} | null;
|
|
54
|
+
/** @deprecated Use body_schema_json */
|
|
42
55
|
body_schema?: Record<string, unknown>;
|
|
56
|
+
/** @deprecated Use example_payload_json */
|
|
43
57
|
example_payload?: Record<string, unknown>;
|
|
44
|
-
curl_example: string;
|
|
45
58
|
}
|
|
46
59
|
|
|
47
60
|
export interface SigningContract {
|
|
@@ -83,10 +96,10 @@ export interface TriggerListResponse {
|
|
|
83
96
|
export interface TriggerInputContractResponse {
|
|
84
97
|
trigger_id: string;
|
|
85
98
|
template_slug?: string;
|
|
86
|
-
external_body_schema?:
|
|
87
|
-
run_input_schema?:
|
|
88
|
-
effective_input_mapping_spec?:
|
|
89
|
-
example_payload?:
|
|
99
|
+
external_body_schema?: JsonSchema;
|
|
100
|
+
run_input_schema?: JsonSchema;
|
|
101
|
+
effective_input_mapping_spec?: TriggerInputMappingSpec;
|
|
102
|
+
example_payload?: JsonSchema;
|
|
90
103
|
has_input_mapping: boolean;
|
|
91
104
|
}
|
|
92
105
|
|
|
@@ -104,6 +117,28 @@ export interface TestMappingResponse {
|
|
|
104
117
|
validation_errors?: MappingValidationError[];
|
|
105
118
|
}
|
|
106
119
|
|
|
120
|
+
export interface InferSchemaPathInfo {
|
|
121
|
+
path: string;
|
|
122
|
+
kind: string;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface InferSchemaResponse {
|
|
126
|
+
inferred_schema: JsonSchema;
|
|
127
|
+
paths: InferSchemaPathInfo[];
|
|
128
|
+
warnings: string[];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface SaveInputMappingResponse {
|
|
132
|
+
trigger_id: string;
|
|
133
|
+
input_mapping_override: TriggerInputMappingSpec;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export interface RegeneratedSecretResponse {
|
|
137
|
+
id: string;
|
|
138
|
+
secret_key: string;
|
|
139
|
+
regenerated_at: string;
|
|
140
|
+
}
|
|
141
|
+
|
|
107
142
|
// =============================================================================
|
|
108
143
|
// Module
|
|
109
144
|
// =============================================================================
|
|
@@ -272,5 +307,51 @@ export class TriggersModule {
|
|
|
272
307
|
headers: this.headers(),
|
|
273
308
|
});
|
|
274
309
|
}
|
|
275
|
-
}
|
|
276
310
|
|
|
311
|
+
/**
|
|
312
|
+
* Regenerate the webhook secret for a trigger.
|
|
313
|
+
*/
|
|
314
|
+
async regenerateSecret(triggerId: string): Promise<APIResponse<RegeneratedSecretResponse>> {
|
|
315
|
+
return this.client.POST<RegeneratedSecretResponse>("/v1/api/triggers/{id}/regenerate-secret", {
|
|
316
|
+
params: { path: { id: triggerId } },
|
|
317
|
+
headers: this.headers(),
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Infer schema from a sample payload.
|
|
323
|
+
*/
|
|
324
|
+
async inferSchema(triggerId: string, samplePayload: unknown): Promise<APIResponse<InferSchemaResponse>> {
|
|
325
|
+
return this.client.POST<InferSchemaResponse>("/v1/api/triggers/{id}/infer-schema", {
|
|
326
|
+
params: { path: { id: triggerId } },
|
|
327
|
+
body: { sample_payload: samplePayload },
|
|
328
|
+
headers: this.headers(),
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Set/update the input mapping for a trigger.
|
|
334
|
+
*/
|
|
335
|
+
async putInputMapping(triggerId: string, inputMappingOverride: TriggerInputMappingSpec): Promise<APIResponse<SaveInputMappingResponse>> {
|
|
336
|
+
return this.client.PUT<SaveInputMappingResponse>("/v1/api/triggers/{id}/input-mapping", {
|
|
337
|
+
params: { path: { id: triggerId } },
|
|
338
|
+
body: { input_mapping_override: inputMappingOverride },
|
|
339
|
+
headers: this.headers(),
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Preview input mapping transformation result.
|
|
345
|
+
*/
|
|
346
|
+
async previewInputMapping(
|
|
347
|
+
triggerId: string,
|
|
348
|
+
samplePayload: unknown,
|
|
349
|
+
inputMappingOverride: TriggerInputMappingSpec
|
|
350
|
+
): Promise<APIResponse<TestMappingResponse>> {
|
|
351
|
+
return this.client.POST<TestMappingResponse>("/v1/api/triggers/{id}/preview-input-mapping", {
|
|
352
|
+
params: { path: { id: triggerId } },
|
|
353
|
+
body: { sample_payload: samplePayload, input_mapping_override: inputMappingOverride },
|
|
354
|
+
headers: this.headers(),
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
}
|
package/src/modules/usage.ts
CHANGED
|
@@ -1,31 +1,116 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Usage Module -
|
|
2
|
+
* Usage Module — Tenant-level usage metrics and quotas.
|
|
3
|
+
*
|
|
4
|
+
* Endpoints: GET /v1/api/quotas, GET /v1/api/usage
|
|
5
|
+
* Source: runtime.cost_events aggregation
|
|
3
6
|
*/
|
|
4
7
|
|
|
5
8
|
import type { RawClient, APIResponse } from "../client/raw.js";
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
// =============================================================================
|
|
11
|
+
// Types
|
|
12
|
+
// =============================================================================
|
|
13
|
+
|
|
14
|
+
export interface QuotaItem {
|
|
9
15
|
limit: number;
|
|
10
16
|
used: number;
|
|
11
17
|
remaining: number;
|
|
12
18
|
}
|
|
13
19
|
|
|
20
|
+
export interface QuotasResponse {
|
|
21
|
+
tenant_id: string;
|
|
22
|
+
workspace_id?: string;
|
|
23
|
+
quotas: {
|
|
24
|
+
runs_per_month: QuotaItem;
|
|
25
|
+
tokens_per_month: QuotaItem;
|
|
26
|
+
agents_max: QuotaItem;
|
|
27
|
+
storage_mb: QuotaItem;
|
|
28
|
+
};
|
|
29
|
+
reset_at: string;
|
|
30
|
+
source: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface UsageAggregated {
|
|
34
|
+
total_runs: number;
|
|
35
|
+
completed_runs: number;
|
|
36
|
+
failed_runs: number;
|
|
37
|
+
llm_events: number;
|
|
38
|
+
total_tokens: number;
|
|
39
|
+
input_tokens: number;
|
|
40
|
+
output_tokens: number;
|
|
41
|
+
total_duration_ms: number;
|
|
42
|
+
estimated_count: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface DailyBreakdownItem {
|
|
46
|
+
date: string;
|
|
47
|
+
runs: number;
|
|
48
|
+
llm_events: number;
|
|
49
|
+
tokens_in: number;
|
|
50
|
+
tokens_out: number;
|
|
51
|
+
duration_ms: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface ProviderBreakdownItem {
|
|
55
|
+
provider: string;
|
|
56
|
+
runs: number;
|
|
57
|
+
llm_events: number;
|
|
58
|
+
tokens: number;
|
|
59
|
+
}
|
|
60
|
+
|
|
14
61
|
export interface UsageResponse {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
62
|
+
tenant_id: string;
|
|
63
|
+
workspace_id?: string;
|
|
64
|
+
period: { from: string; to: string };
|
|
65
|
+
usage: UsageAggregated;
|
|
66
|
+
daily_breakdown: DailyBreakdownItem[];
|
|
67
|
+
provider_breakdown: ProviderBreakdownItem[];
|
|
68
|
+
source: string;
|
|
19
69
|
}
|
|
20
70
|
|
|
71
|
+
// =============================================================================
|
|
72
|
+
// Module
|
|
73
|
+
// =============================================================================
|
|
74
|
+
|
|
21
75
|
export class UsageModule {
|
|
22
76
|
constructor(private client: RawClient, private headers: () => Record<string, string>) { }
|
|
23
77
|
|
|
24
78
|
/**
|
|
25
|
-
* Get current
|
|
79
|
+
* Get current quota status (tenant-level).
|
|
26
80
|
*/
|
|
27
|
-
async
|
|
81
|
+
async getQuotas(params?: {
|
|
82
|
+
workspaceId?: string;
|
|
83
|
+
/** @deprecated Use workspaceId */
|
|
84
|
+
workspace_id?: string;
|
|
85
|
+
}): Promise<APIResponse<QuotasResponse>> {
|
|
86
|
+
const query = {
|
|
87
|
+
workspaceId: params?.workspaceId ?? params?.workspace_id,
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
return this.client.GET<QuotasResponse>("/v1/api/quotas", {
|
|
91
|
+
params: { query },
|
|
92
|
+
headers: this.headers(),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Get usage metrics with real data from runtime.cost_events.
|
|
98
|
+
*/
|
|
99
|
+
async getUsage(params?: {
|
|
100
|
+
workspaceId?: string;
|
|
101
|
+
/** @deprecated Use workspaceId */
|
|
102
|
+
workspace_id?: string;
|
|
103
|
+
from?: string;
|
|
104
|
+
to?: string;
|
|
105
|
+
}): Promise<APIResponse<UsageResponse>> {
|
|
106
|
+
const query = {
|
|
107
|
+
workspaceId: params?.workspaceId ?? params?.workspace_id,
|
|
108
|
+
from: params?.from,
|
|
109
|
+
to: params?.to,
|
|
110
|
+
};
|
|
111
|
+
|
|
28
112
|
return this.client.GET<UsageResponse>("/v1/api/usage", {
|
|
113
|
+
params: { query },
|
|
29
114
|
headers: this.headers(),
|
|
30
115
|
});
|
|
31
116
|
}
|
|
@@ -11,7 +11,6 @@ type VectorStoreFileResponse = components["schemas"]["VectorStoreFileResponse"];
|
|
|
11
11
|
export interface VectorStore {
|
|
12
12
|
id: string;
|
|
13
13
|
name: string;
|
|
14
|
-
workspace_id: string;
|
|
15
14
|
embedding_provider: string;
|
|
16
15
|
embedding_model: string;
|
|
17
16
|
dimension: number;
|
|
@@ -52,6 +51,42 @@ export interface VectorStoreFilesResponse {
|
|
|
52
51
|
total: number;
|
|
53
52
|
}
|
|
54
53
|
|
|
54
|
+
type VectorStoreLike = VectorStoreResponse & {
|
|
55
|
+
embeddingProvider?: string;
|
|
56
|
+
embeddingModel?: string;
|
|
57
|
+
credentialBindingAlias?: string;
|
|
58
|
+
fileCount?: number;
|
|
59
|
+
createdAt?: string;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
type VectorStoreFileLike = VectorStoreFileResponse & {
|
|
63
|
+
fileId?: string;
|
|
64
|
+
createdAt?: string;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
function toVectorStore(item: VectorStoreLike): VectorStore {
|
|
68
|
+
return {
|
|
69
|
+
id: item.id ?? "",
|
|
70
|
+
name: item.name ?? "",
|
|
71
|
+
embedding_provider: item.embedding_provider ?? item.embeddingProvider ?? "",
|
|
72
|
+
embedding_model: item.embedding_model ?? item.embeddingModel ?? "",
|
|
73
|
+
dimension: item.dimension ?? 0,
|
|
74
|
+
credential_binding_alias: item.credential_binding_alias ?? item.credentialBindingAlias ?? undefined,
|
|
75
|
+
file_count: item.file_count ?? item.fileCount ?? 0,
|
|
76
|
+
created_at: item.created_at ?? item.createdAt ?? "",
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function toVectorStoreFile(item: VectorStoreFileLike): VectorStoreFile {
|
|
81
|
+
return {
|
|
82
|
+
id: item.id ?? "",
|
|
83
|
+
file_id: item.file_id ?? item.fileId ?? "",
|
|
84
|
+
filename: item.filename ?? "",
|
|
85
|
+
status: (item.status ?? "pending") as VectorStoreFile["status"],
|
|
86
|
+
created_at: item.created_at ?? item.createdAt ?? "",
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
55
90
|
export class VectorStoresModule {
|
|
56
91
|
constructor(private client: RawClient, private headers: () => Record<string, string>) { }
|
|
57
92
|
|
|
@@ -63,20 +98,41 @@ export class VectorStoresModule {
|
|
|
63
98
|
limit?: number;
|
|
64
99
|
offset?: number;
|
|
65
100
|
}): Promise<APIResponse<VectorStoreListResponse>> {
|
|
66
|
-
|
|
101
|
+
const response = await this.client.GET<VectorStoreResponse[]>("/v1/api/vector-stores", {
|
|
67
102
|
params: { query: params },
|
|
68
103
|
headers: this.headers(),
|
|
69
104
|
});
|
|
105
|
+
|
|
106
|
+
const items = Array.isArray(response.data)
|
|
107
|
+
? response.data.map((item) => toVectorStore(item))
|
|
108
|
+
: [];
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
...response,
|
|
112
|
+
data: {
|
|
113
|
+
items,
|
|
114
|
+
total: items.length,
|
|
115
|
+
},
|
|
116
|
+
};
|
|
70
117
|
}
|
|
71
118
|
|
|
72
119
|
/**
|
|
73
120
|
* Get a vector store by ID.
|
|
74
121
|
*/
|
|
75
122
|
async get(storeId: string): Promise<APIResponse<VectorStore>> {
|
|
76
|
-
|
|
77
|
-
params: { path: {
|
|
123
|
+
const response = await this.client.GET<VectorStoreResponse>("/v1/api/vector-stores/{vectorStoreId}", {
|
|
124
|
+
params: { path: { vectorStoreId: storeId } },
|
|
78
125
|
headers: this.headers(),
|
|
79
126
|
});
|
|
127
|
+
|
|
128
|
+
if (!response.data) {
|
|
129
|
+
return response as APIResponse<VectorStore>;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
...response,
|
|
134
|
+
data: toVectorStore(response.data),
|
|
135
|
+
};
|
|
80
136
|
}
|
|
81
137
|
|
|
82
138
|
/**
|
|
@@ -89,18 +145,27 @@ export class VectorStoresModule {
|
|
|
89
145
|
dimension?: number;
|
|
90
146
|
credential_binding_alias?: string;
|
|
91
147
|
}): Promise<APIResponse<VectorStore>> {
|
|
92
|
-
|
|
148
|
+
const response = await this.client.POST<VectorStoreResponse>("/v1/api/vector-stores", {
|
|
93
149
|
body,
|
|
94
150
|
headers: this.headers(),
|
|
95
151
|
});
|
|
152
|
+
|
|
153
|
+
if (!response.data) {
|
|
154
|
+
return response as APIResponse<VectorStore>;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
...response,
|
|
159
|
+
data: toVectorStore(response.data),
|
|
160
|
+
};
|
|
96
161
|
}
|
|
97
162
|
|
|
98
163
|
/**
|
|
99
164
|
* Delete a vector store.
|
|
100
165
|
*/
|
|
101
166
|
async delete(storeId: string): Promise<APIResponse<void>> {
|
|
102
|
-
return this.client.DELETE<void>("/v1/api/vector-stores/{
|
|
103
|
-
params: { path: {
|
|
167
|
+
return this.client.DELETE<void>("/v1/api/vector-stores/{vectorStoreId}", {
|
|
168
|
+
params: { path: { vectorStoreId: storeId } },
|
|
104
169
|
headers: this.headers(),
|
|
105
170
|
});
|
|
106
171
|
}
|
|
@@ -115,11 +180,11 @@ export class VectorStoresModule {
|
|
|
115
180
|
top_k?: number;
|
|
116
181
|
min_score?: number;
|
|
117
182
|
}): Promise<APIResponse<VectorQueryResult>> {
|
|
118
|
-
return this.client.POST<
|
|
119
|
-
params: { path: {
|
|
183
|
+
return this.client.POST<VectorQueryResponse>("/v1/api/vector-stores/{vectorStoreId}/query", {
|
|
184
|
+
params: { path: { vectorStoreId: storeId } },
|
|
120
185
|
body,
|
|
121
186
|
headers: this.headers(),
|
|
122
|
-
})
|
|
187
|
+
}) as Promise<APIResponse<VectorQueryResult>>;
|
|
123
188
|
}
|
|
124
189
|
|
|
125
190
|
// ======================== Files ========================
|
|
@@ -128,32 +193,64 @@ export class VectorStoresModule {
|
|
|
128
193
|
* List files in a vector store.
|
|
129
194
|
*/
|
|
130
195
|
async listFiles(storeId: string, params?: {
|
|
131
|
-
|
|
132
|
-
|
|
196
|
+
skip?: number;
|
|
197
|
+
take?: number;
|
|
133
198
|
}): Promise<APIResponse<VectorStoreFilesResponse>> {
|
|
134
|
-
|
|
135
|
-
params: { path: {
|
|
199
|
+
const response = await this.client.GET<VectorStoreFileResponse[]>("/v1/api/vector-stores/{vectorStoreId}/files", {
|
|
200
|
+
params: { path: { vectorStoreId: storeId }, query: params },
|
|
136
201
|
headers: this.headers(),
|
|
137
202
|
});
|
|
203
|
+
|
|
204
|
+
const items = Array.isArray(response.data)
|
|
205
|
+
? response.data.map((item) => toVectorStoreFile(item))
|
|
206
|
+
: [];
|
|
207
|
+
|
|
208
|
+
return {
|
|
209
|
+
...response,
|
|
210
|
+
data: {
|
|
211
|
+
items,
|
|
212
|
+
total: items.length,
|
|
213
|
+
},
|
|
214
|
+
};
|
|
138
215
|
}
|
|
139
216
|
|
|
140
217
|
/**
|
|
141
218
|
* Attach a file to a vector store.
|
|
142
219
|
*/
|
|
143
220
|
async attachFile(storeId: string, fileId: string): Promise<APIResponse<VectorStoreFile>> {
|
|
144
|
-
|
|
145
|
-
params: { path: {
|
|
221
|
+
const response = await this.client.POST<VectorStoreFileResponse>("/v1/api/vector-stores/{vectorStoreId}/files", {
|
|
222
|
+
params: { path: { vectorStoreId: storeId } },
|
|
146
223
|
body: { file_id: fileId },
|
|
147
224
|
headers: this.headers(),
|
|
148
225
|
});
|
|
226
|
+
|
|
227
|
+
if (!response.data) {
|
|
228
|
+
return response as APIResponse<VectorStoreFile>;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return {
|
|
232
|
+
...response,
|
|
233
|
+
data: toVectorStoreFile(response.data),
|
|
234
|
+
};
|
|
149
235
|
}
|
|
150
236
|
|
|
151
237
|
/**
|
|
152
238
|
* Remove a file from a vector store.
|
|
153
239
|
*/
|
|
154
240
|
async removeFile(storeId: string, fileId: string): Promise<APIResponse<void>> {
|
|
155
|
-
return this.client.DELETE<void>("/v1/api/vector-stores/{
|
|
156
|
-
params: { path: {
|
|
241
|
+
return this.client.DELETE<void>("/v1/api/vector-stores/{vectorStoreId}/files/{fileId}", {
|
|
242
|
+
params: { path: { vectorStoreId: storeId, fileId } },
|
|
243
|
+
headers: this.headers(),
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Bind a vector store to an agent.
|
|
249
|
+
*/
|
|
250
|
+
async bindAgent(storeId: string, agentId: string): Promise<APIResponse<void>> {
|
|
251
|
+
return this.client.POST<void>("/v1/api/vector-stores/{vectorStoreId}/bind-agent", {
|
|
252
|
+
params: { path: { vectorStoreId: storeId } },
|
|
253
|
+
body: { agent_id: agentId },
|
|
157
254
|
headers: this.headers(),
|
|
158
255
|
});
|
|
159
256
|
}
|
package/src/modules/knowledge.ts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Knowledge Module - Fully Typed
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { RawClient, APIResponse } from "../client/raw.js";
|
|
6
|
-
|
|
7
|
-
export interface KnowledgeDataset {
|
|
8
|
-
id: string;
|
|
9
|
-
name: string;
|
|
10
|
-
description?: string;
|
|
11
|
-
workspace_id: string;
|
|
12
|
-
file_count: number;
|
|
13
|
-
total_chunks: number;
|
|
14
|
-
created_at: string;
|
|
15
|
-
updated_at: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface KnowledgeListResponse {
|
|
19
|
-
items: KnowledgeDataset[];
|
|
20
|
-
total: number;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface KnowledgeFile {
|
|
24
|
-
id: string;
|
|
25
|
-
dataset_id: string;
|
|
26
|
-
filename: string;
|
|
27
|
-
size_bytes: number;
|
|
28
|
-
chunk_count: number;
|
|
29
|
-
status: "pending" | "processing" | "completed" | "failed";
|
|
30
|
-
created_at: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface KnowledgeFileListResponse {
|
|
34
|
-
items: KnowledgeFile[];
|
|
35
|
-
total: number;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface KnowledgeSearchResult {
|
|
39
|
-
chunk_id: string;
|
|
40
|
-
file_id: string;
|
|
41
|
-
content: string;
|
|
42
|
-
score: number;
|
|
43
|
-
metadata?: Record<string, unknown>;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface KnowledgeSearchResponse {
|
|
47
|
-
results: KnowledgeSearchResult[];
|
|
48
|
-
total: number;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export class KnowledgeModule {
|
|
52
|
-
constructor(
|
|
53
|
-
private client: RawClient,
|
|
54
|
-
private getWorkspaceId: () => string,
|
|
55
|
-
private headers: () => Record<string, string>
|
|
56
|
-
) { }
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* List all knowledge datasets.
|
|
60
|
-
*/
|
|
61
|
-
async list(params?: {
|
|
62
|
-
workspace_id?: string;
|
|
63
|
-
limit?: number;
|
|
64
|
-
offset?: number;
|
|
65
|
-
}): Promise<APIResponse<KnowledgeListResponse>> {
|
|
66
|
-
return this.client.GET<KnowledgeListResponse>("/v1/api/knowledge", {
|
|
67
|
-
params: { query: params },
|
|
68
|
-
headers: this.headers(),
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Get a knowledge dataset by ID.
|
|
74
|
-
*/
|
|
75
|
-
async get(datasetId: string): Promise<APIResponse<KnowledgeDataset>> {
|
|
76
|
-
return this.client.GET<KnowledgeDataset>("/v1/api/knowledge/{id}", {
|
|
77
|
-
params: { path: { id: datasetId } },
|
|
78
|
-
headers: this.headers(),
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Create a new knowledge dataset.
|
|
84
|
-
*/
|
|
85
|
-
async create(body: {
|
|
86
|
-
name: string;
|
|
87
|
-
description?: string;
|
|
88
|
-
}): Promise<APIResponse<KnowledgeDataset>> {
|
|
89
|
-
return this.client.POST<KnowledgeDataset>("/v1/api/knowledge", {
|
|
90
|
-
body,
|
|
91
|
-
headers: this.headers(),
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Delete a knowledge dataset.
|
|
97
|
-
*/
|
|
98
|
-
async delete(datasetId: string): Promise<APIResponse<void>> {
|
|
99
|
-
return this.client.DELETE<void>("/v1/api/knowledge/{id}", {
|
|
100
|
-
params: { path: { id: datasetId } },
|
|
101
|
-
headers: this.headers(),
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// ======================== Files ========================
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* List files in a dataset.
|
|
109
|
-
*/
|
|
110
|
-
async listFiles(datasetId: string, params?: {
|
|
111
|
-
limit?: number;
|
|
112
|
-
offset?: number;
|
|
113
|
-
}): Promise<APIResponse<KnowledgeFileListResponse>> {
|
|
114
|
-
return this.client.GET<KnowledgeFileListResponse>("/v1/api/knowledge/{id}/files", {
|
|
115
|
-
params: { path: { id: datasetId }, query: params },
|
|
116
|
-
headers: this.headers(),
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Add a file to a dataset.
|
|
122
|
-
*/
|
|
123
|
-
async addFile(datasetId: string, fileId: string): Promise<APIResponse<KnowledgeFile>> {
|
|
124
|
-
return this.client.POST<KnowledgeFile>("/v1/api/knowledge/{id}/files", {
|
|
125
|
-
params: { path: { id: datasetId } },
|
|
126
|
-
body: { file_id: fileId },
|
|
127
|
-
headers: this.headers(),
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// ======================== Search ========================
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Search within a knowledge dataset.
|
|
135
|
-
*/
|
|
136
|
-
async search(datasetId: string, body: {
|
|
137
|
-
query: string;
|
|
138
|
-
top_k?: number;
|
|
139
|
-
min_score?: number;
|
|
140
|
-
}): Promise<APIResponse<KnowledgeSearchResponse>> {
|
|
141
|
-
return this.client.POST<KnowledgeSearchResponse>("/v1/api/knowledge/{id}/search", {
|
|
142
|
-
params: { path: { id: datasetId } },
|
|
143
|
-
body,
|
|
144
|
-
headers: this.headers(),
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
}
|