@openagentpack/sdk 0.3.0-beta-e537ab3-20260722 → 0.3.0-beta-8d9edcd-20260722
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/index.d.ts +14 -1
- package/dist/index.js +210 -173
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -745,6 +745,19 @@ interface ProviderAdapter {
|
|
|
745
745
|
downloadAllSkillFiles?(): Promise<Map<string, SkillFile[]>>;
|
|
746
746
|
}
|
|
747
747
|
|
|
748
|
+
declare class ApiError extends Error {
|
|
749
|
+
readonly statusCode: number;
|
|
750
|
+
readonly responseBody: string;
|
|
751
|
+
constructor(statusCode: number, responseBody: string, prefix: string);
|
|
752
|
+
static isNotFound(err: unknown): boolean;
|
|
753
|
+
}
|
|
754
|
+
declare class ConflictError extends ApiError {
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
type FetchLike = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
758
|
+
/** Install the fetch implementation used by all provider clients; pass undefined to reset. */
|
|
759
|
+
declare function setDefaultFetch(fetchImpl: FetchLike | undefined): void;
|
|
760
|
+
|
|
748
761
|
interface IStateManager {
|
|
749
762
|
getResource(address: ResourceAddress): ResourceState | undefined;
|
|
750
763
|
setResource(resource: ResourceState): void;
|
|
@@ -1461,4 +1474,4 @@ declare class LocalFileStateBackend implements StateBackend {
|
|
|
1461
1474
|
/** Normalize a skill zip and extract its entries to SkillFile[]. */
|
|
1462
1475
|
declare function extractSkillZipFiles(raw: Buffer): Promise<SkillFile[]>;
|
|
1463
1476
|
|
|
1464
|
-
export { AGENTS_CONFIG_PROVIDERS, AGENTS_PROVIDER_FIELDS, type AgentBuildInput, AgentDefinition, type AgentMcpBuildInput, type AgentSkillBuildInput, AgentSyncRun, AgentWithReadiness, type BackendRuntimeInput, type BatchCreateMemoryInput, type BatchCreateMemoryResult, CloudAgent, CloudEnvironment, CloudVault, type CollectedSessionEvents, type CreateMemoryInput, type CreateMemoryStoreInput, type DeploymentListFilter, type DeploymentListResult, type DestroyResourceResult, type DestructivePolicy, Diagnostic, type IStateManager, type LoadedProjectConfig, LocalFileStateBackend, type MemoryInfo, type MemoryListItem, type MemoryListOptions, type MemoryPage, type MemoryPrefixInfo, type MemoryProviderCapabilities, type MemoryStoreInfo, type MemoryStoreListOptions, type MemoryVersionInfo, type MemoryVersionListOptions, type MigrateOptions, type MigrateResult, PlannedAction, type ProjectRuntimeContext, type ProviderConfig, type ProviderConfigProvider, ProviderFileInfo, ProviderSessionEvent, type ProviderSessionInfo, type ProviderSkillInfo, type ResolvedProjectConfig, type ResourceActionResult, ResourceAddress, type ResourceExecutionResult, type ResourcePlanResult, type ResourceRefreshResult, type ResourceRuntimeOptions, type ResourceState, type ResourceSyncRun, ResourceType, type RuntimeFeedbackEvent, type RuntimeFeedbackSink, type SecretPlaceholder, type SkillFile, StateManager, type StateScope, type SyncProjectOptions, type SyncProjectResult, type UpdateMemoryInput, type UpdateMemoryStoreInput, UserError, type ValidateProjectConfigOptions, applyProviderConfigToEnv, archiveCloudAgent, archiveMemoryStore, areRuntimeCredentialsReady, batchCreateMemories, bootstrapRuntimeCredentials, bootstrapRuntimeCredentialsSync, buildAgentDecl, collectConfigReferences, createCloudEnvironment, createCloudVault, createMemory, createMemoryStore, createProjectRuntime, createSessionForAgent, createSkillFromFileId, decideDestructive, deleteCloudEnvironment, deleteCloudVault, deleteFile, deleteMemory, deleteMemoryStore, deleteSession, deleteSkill, destroyPlannedProjectResources, executePlannedProject, extractSkillZipFiles, getAgent, getDeploymentDetailsForContext, getDeploymentRuntimeProviderForContext, getFileDownloadUrl, getFileInfo, getMemory, getMemoryProviderCapabilities, getMemoryStore, getMemoryVersion, getSession, getSkillInfo, importResource, isTerminalSessionStatus, listAgentsWithReadiness, listCloudAgents, listCloudEnvironments, listCloudVaults, listDeploymentsForContext, listFiles, listMemories, listMemoryStores, listMemoryVersions, listProviderModelsForContext, listProviderNames, listRemoteDeploymentsForContext, listSessionEvents, listSessionSummaries, listSkills, loadDotEnv, loadProviderConfigIntoEnv, loadProviderConfigIntoEnvSync, migrateConfig, parseStateAddress, pauseDeploymentForContext, planDestroyProjectContext, planProjectContext, prepareInitialSessionPrompt, preparePromptForProvider, prependFileHint, providerConfigPath, readProjectRuntime, redactMemoryVersion, resolveActiveProvider, resolveProjectConfig, resolveProjectConfigFromObject, resolveProviderConfigFromEnv, resolveRepositoryMountPath, resolveSessionProvider, resolveSyncProvider, rewriteFileMentions, runDeploymentForContext, sendSessionMessagePolling, sendSessionMessageStreaming, startSessionRun, startSessionRunPolling, streamSessionEvents, syncAgentResourcesWithStateBackend, syncProjectResourcesWithStateBackend, syncProviderResourcesFromContext, syncProviderResourcesFromEnv, updateMemory, updateMemoryStore, uploadFile, validateProjectConfig, writeProjectRuntime };
|
|
1477
|
+
export { AGENTS_CONFIG_PROVIDERS, AGENTS_PROVIDER_FIELDS, type AgentBuildInput, AgentDefinition, type AgentMcpBuildInput, type AgentSkillBuildInput, AgentSyncRun, AgentWithReadiness, ApiError, type BackendRuntimeInput, type BatchCreateMemoryInput, type BatchCreateMemoryResult, CloudAgent, CloudEnvironment, CloudVault, type CollectedSessionEvents, ConflictError, type CreateMemoryInput, type CreateMemoryStoreInput, type DeploymentListFilter, type DeploymentListResult, type DestroyResourceResult, type DestructivePolicy, Diagnostic, type FetchLike, type IStateManager, type LoadedProjectConfig, LocalFileStateBackend, type MemoryInfo, type MemoryListItem, type MemoryListOptions, type MemoryPage, type MemoryPrefixInfo, type MemoryProviderCapabilities, type MemoryStoreInfo, type MemoryStoreListOptions, type MemoryVersionInfo, type MemoryVersionListOptions, type MigrateOptions, type MigrateResult, PlannedAction, type ProjectRuntimeContext, type ProviderConfig, type ProviderConfigProvider, ProviderFileInfo, ProviderSessionEvent, type ProviderSessionInfo, type ProviderSkillInfo, type ResolvedProjectConfig, type ResourceActionResult, ResourceAddress, type ResourceExecutionResult, type ResourcePlanResult, type ResourceRefreshResult, type ResourceRuntimeOptions, type ResourceState, type ResourceSyncRun, ResourceType, type RuntimeFeedbackEvent, type RuntimeFeedbackSink, type SecretPlaceholder, type SkillFile, StateManager, type StateScope, type SyncProjectOptions, type SyncProjectResult, type UpdateMemoryInput, type UpdateMemoryStoreInput, UserError, type ValidateProjectConfigOptions, applyProviderConfigToEnv, archiveCloudAgent, archiveMemoryStore, areRuntimeCredentialsReady, batchCreateMemories, bootstrapRuntimeCredentials, bootstrapRuntimeCredentialsSync, buildAgentDecl, collectConfigReferences, createCloudEnvironment, createCloudVault, createMemory, createMemoryStore, createProjectRuntime, createSessionForAgent, createSkillFromFileId, decideDestructive, deleteCloudEnvironment, deleteCloudVault, deleteFile, deleteMemory, deleteMemoryStore, deleteSession, deleteSkill, destroyPlannedProjectResources, executePlannedProject, extractSkillZipFiles, getAgent, getDeploymentDetailsForContext, getDeploymentRuntimeProviderForContext, getFileDownloadUrl, getFileInfo, getMemory, getMemoryProviderCapabilities, getMemoryStore, getMemoryVersion, getSession, getSkillInfo, importResource, isTerminalSessionStatus, listAgentsWithReadiness, listCloudAgents, listCloudEnvironments, listCloudVaults, listDeploymentsForContext, listFiles, listMemories, listMemoryStores, listMemoryVersions, listProviderModelsForContext, listProviderNames, listRemoteDeploymentsForContext, listSessionEvents, listSessionSummaries, listSkills, loadDotEnv, loadProviderConfigIntoEnv, loadProviderConfigIntoEnvSync, migrateConfig, parseStateAddress, pauseDeploymentForContext, planDestroyProjectContext, planProjectContext, prepareInitialSessionPrompt, preparePromptForProvider, prependFileHint, providerConfigPath, readProjectRuntime, redactMemoryVersion, resolveActiveProvider, resolveProjectConfig, resolveProjectConfigFromObject, resolveProviderConfigFromEnv, resolveRepositoryMountPath, resolveSessionProvider, resolveSyncProvider, rewriteFileMentions, runDeploymentForContext, sendSessionMessagePolling, sendSessionMessageStreaming, setDefaultFetch, startSessionRun, startSessionRunPolling, streamSessionEvents, syncAgentResourcesWithStateBackend, syncProjectResourcesWithStateBackend, syncProviderResourcesFromContext, syncProviderResourcesFromEnv, updateMemory, updateMemoryStore, uploadFile, validateProjectConfig, writeProjectRuntime };
|
package/dist/index.js
CHANGED
|
@@ -24,6 +24,178 @@ var UserError = class extends Error {
|
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
+
// src/internal/transport.ts
|
|
28
|
+
var defaultFetch;
|
|
29
|
+
function setDefaultFetch(fetchImpl) {
|
|
30
|
+
defaultFetch = fetchImpl;
|
|
31
|
+
}
|
|
32
|
+
function resolveFetch() {
|
|
33
|
+
return defaultFetch ?? ((input, init) => fetch(input, init));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/internal/providers/base-client.ts
|
|
37
|
+
var ApiError = class _ApiError extends Error {
|
|
38
|
+
constructor(statusCode, responseBody, prefix) {
|
|
39
|
+
super(`${prefix} ${statusCode}: ${responseBody}`);
|
|
40
|
+
this.statusCode = statusCode;
|
|
41
|
+
this.responseBody = responseBody;
|
|
42
|
+
}
|
|
43
|
+
statusCode;
|
|
44
|
+
responseBody;
|
|
45
|
+
static isNotFound(err) {
|
|
46
|
+
return err instanceof _ApiError && err.statusCode === 404;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var ConflictError = class extends ApiError {
|
|
50
|
+
};
|
|
51
|
+
var BaseApiClient = class {
|
|
52
|
+
isConflict(_status, _body) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
async throwIfError(res) {
|
|
56
|
+
if (res.ok) return;
|
|
57
|
+
const body = await res.text();
|
|
58
|
+
if (this.isConflict(res.status, body)) throw new ConflictError(res.status, body, this.errorPrefix);
|
|
59
|
+
throw new ApiError(res.status, body, this.errorPrefix);
|
|
60
|
+
}
|
|
61
|
+
async post(path, body) {
|
|
62
|
+
const res = await resolveFetch()(`${this.baseUrl}${path}`, {
|
|
63
|
+
method: "POST",
|
|
64
|
+
headers: this.headers(),
|
|
65
|
+
body: JSON.stringify(body)
|
|
66
|
+
});
|
|
67
|
+
await this.throwIfError(res);
|
|
68
|
+
return res.json();
|
|
69
|
+
}
|
|
70
|
+
async put(path, body) {
|
|
71
|
+
const res = await resolveFetch()(`${this.baseUrl}${path}`, {
|
|
72
|
+
method: "PUT",
|
|
73
|
+
headers: this.headers(),
|
|
74
|
+
body: JSON.stringify(body)
|
|
75
|
+
});
|
|
76
|
+
await this.throwIfError(res);
|
|
77
|
+
return res.json();
|
|
78
|
+
}
|
|
79
|
+
async delete(path) {
|
|
80
|
+
const res = await resolveFetch()(`${this.baseUrl}${path}`, {
|
|
81
|
+
method: "DELETE",
|
|
82
|
+
headers: this.headers()
|
|
83
|
+
});
|
|
84
|
+
await this.throwIfError(res);
|
|
85
|
+
}
|
|
86
|
+
async get(path) {
|
|
87
|
+
const res = await resolveFetch()(`${this.baseUrl}${path}`, {
|
|
88
|
+
method: "GET",
|
|
89
|
+
headers: this.headers()
|
|
90
|
+
});
|
|
91
|
+
await this.throwIfError(res);
|
|
92
|
+
return res.json();
|
|
93
|
+
}
|
|
94
|
+
async getBuffer(path) {
|
|
95
|
+
const res = await resolveFetch()(`${this.baseUrl}${path}`, {
|
|
96
|
+
method: "GET",
|
|
97
|
+
headers: this.headers()
|
|
98
|
+
});
|
|
99
|
+
await this.throwIfError(res);
|
|
100
|
+
return Buffer.from(await res.arrayBuffer());
|
|
101
|
+
}
|
|
102
|
+
async *sse(path, options) {
|
|
103
|
+
const controller = new AbortController();
|
|
104
|
+
const res = await resolveFetch()(`${this.baseUrl}${path}`, {
|
|
105
|
+
method: "GET",
|
|
106
|
+
headers: { ...this.headers(), Accept: "text/event-stream", ...options?.headers },
|
|
107
|
+
signal: controller.signal
|
|
108
|
+
});
|
|
109
|
+
await this.throwIfError(res);
|
|
110
|
+
const reader = res.body.getReader();
|
|
111
|
+
const decoder = new TextDecoder();
|
|
112
|
+
let buffer = "";
|
|
113
|
+
try {
|
|
114
|
+
while (true) {
|
|
115
|
+
const { done, value } = await reader.read();
|
|
116
|
+
if (done) break;
|
|
117
|
+
buffer += decoder.decode(value, { stream: true });
|
|
118
|
+
let boundary = buffer.indexOf("\n\n");
|
|
119
|
+
while (boundary !== -1) {
|
|
120
|
+
const frame = buffer.slice(0, boundary);
|
|
121
|
+
buffer = buffer.slice(boundary + 2);
|
|
122
|
+
boundary = buffer.indexOf("\n\n");
|
|
123
|
+
const dataLines = [];
|
|
124
|
+
let sseId;
|
|
125
|
+
for (const line of frame.split("\n")) {
|
|
126
|
+
if (line.startsWith(":")) continue;
|
|
127
|
+
if (line.startsWith("event:") && line.slice(6).trim() === "heartbeat") {
|
|
128
|
+
dataLines.length = 0;
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
if (line.startsWith("data:")) {
|
|
132
|
+
dataLines.push(line.slice(5).trimStart());
|
|
133
|
+
}
|
|
134
|
+
if (line.startsWith("id:")) {
|
|
135
|
+
sseId = line.slice(3).trimStart();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (dataLines.length === 0) continue;
|
|
139
|
+
const json = dataLines.join("\n");
|
|
140
|
+
try {
|
|
141
|
+
const parsed = JSON.parse(json);
|
|
142
|
+
if (sseId !== void 0 && parsed.id === void 0) {
|
|
143
|
+
parsed.id = sseId;
|
|
144
|
+
}
|
|
145
|
+
yield parsed;
|
|
146
|
+
} catch {
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
} finally {
|
|
151
|
+
try {
|
|
152
|
+
await reader.cancel();
|
|
153
|
+
} catch {
|
|
154
|
+
}
|
|
155
|
+
controller.abort();
|
|
156
|
+
reader.releaseLock();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async postFormData(path, formData) {
|
|
160
|
+
const { "Content-Type": _contentType, ...headers } = this.headers();
|
|
161
|
+
const res = await resolveFetch()(`${this.baseUrl}${path}`, {
|
|
162
|
+
method: "POST",
|
|
163
|
+
headers,
|
|
164
|
+
body: formData
|
|
165
|
+
});
|
|
166
|
+
await this.throwIfError(res);
|
|
167
|
+
return res.json();
|
|
168
|
+
}
|
|
169
|
+
async getAllPaged(path) {
|
|
170
|
+
const all = [];
|
|
171
|
+
let cursor;
|
|
172
|
+
for (; ; ) {
|
|
173
|
+
const sep = path.includes("?") ? "&" : "?";
|
|
174
|
+
const param = this.paginationStrategy === "page" ? "page" : "after_id";
|
|
175
|
+
const url = cursor ? `${path}${sep}limit=100&${param}=${encodeURIComponent(cursor)}` : `${path}${sep}limit=100`;
|
|
176
|
+
const res = await this.get(url);
|
|
177
|
+
const data = res.data ?? [];
|
|
178
|
+
all.push(...data);
|
|
179
|
+
if (data.length === 0) break;
|
|
180
|
+
if (this.paginationStrategy === "page") {
|
|
181
|
+
if (!res.next_page) break;
|
|
182
|
+
cursor = res.next_page;
|
|
183
|
+
} else {
|
|
184
|
+
if (!res.has_more || !res.last_id) break;
|
|
185
|
+
cursor = res.last_id;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return all;
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
function toRemoteResource(res) {
|
|
192
|
+
return {
|
|
193
|
+
id: res.id,
|
|
194
|
+
type: res.type,
|
|
195
|
+
version: res.version
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
27
199
|
// src/internal/providers/capabilities.ts
|
|
28
200
|
function isSupported(caps, kind) {
|
|
29
201
|
const tier = caps?.[kind]?.tier;
|
|
@@ -80,6 +252,16 @@ function getProvider(name) {
|
|
|
80
252
|
function allProviders() {
|
|
81
253
|
return Array.from(registry.values());
|
|
82
254
|
}
|
|
255
|
+
function parseProviderConfig(def, rawConfig) {
|
|
256
|
+
const result = def.configSchema.safeParse(rawConfig);
|
|
257
|
+
if (result.success) return result.data;
|
|
258
|
+
const details = result.error.issues.map((issue) => {
|
|
259
|
+
const path = issue.path.join(".");
|
|
260
|
+
return path ? `${path}: ${issue.message}` : issue.message;
|
|
261
|
+
});
|
|
262
|
+
throw new UserError(`Provider '${def.name}' config invalid:
|
|
263
|
+
${details.join("\n")}`);
|
|
264
|
+
}
|
|
83
265
|
function buildProviders(providersConfig, projectName) {
|
|
84
266
|
const adapters = /* @__PURE__ */ new Map();
|
|
85
267
|
for (const [name, rawConfig] of Object.entries(providersConfig)) {
|
|
@@ -87,7 +269,7 @@ function buildProviders(providersConfig, projectName) {
|
|
|
87
269
|
if (!def) {
|
|
88
270
|
throw new UserError(`Unknown provider '${name}'. Registered: ${Array.from(registry.keys()).join(", ")}`);
|
|
89
271
|
}
|
|
90
|
-
const parsed = def
|
|
272
|
+
const parsed = parseProviderConfig(def, rawConfig);
|
|
91
273
|
const adapter2 = def.createAdapter(parsed, projectName);
|
|
92
274
|
validateProviderFacets(def, adapter2);
|
|
93
275
|
adapters.set(name, adapter2);
|
|
@@ -97,8 +279,11 @@ function buildProviders(providersConfig, projectName) {
|
|
|
97
279
|
var PROVIDER_ENV_VARS = {
|
|
98
280
|
bailian: {
|
|
99
281
|
api_key: { env: ["DASHSCOPE_API_KEY", "BAILIAN_API_KEY"], required: true },
|
|
100
|
-
workspace_id
|
|
101
|
-
|
|
282
|
+
// Neither workspace_id nor base_url is required on its own; the config schema
|
|
283
|
+
// enforces "at least one" so a host can supply just base_url (BAILIAN_BASE_URL).
|
|
284
|
+
// base_url is the preferred placeholder emitted by `agents sync`.
|
|
285
|
+
workspace_id: { env: ["BAILIAN_WORKSPACE_ID"], required: false },
|
|
286
|
+
base_url: { env: ["BAILIAN_BASE_URL"], required: false, placeholder: true }
|
|
102
287
|
},
|
|
103
288
|
qoder: {
|
|
104
289
|
api_key: { env: ["QODER_PAT", "QODER_API_KEY"], required: true },
|
|
@@ -117,8 +302,8 @@ function placeholderProviderConfig(providerName) {
|
|
|
117
302
|
const envMap = PROVIDER_ENV_VARS[providerName];
|
|
118
303
|
if (!envMap) return {};
|
|
119
304
|
const out = {};
|
|
120
|
-
for (const [field, { env, required }] of Object.entries(envMap)) {
|
|
121
|
-
if (required && env[0]) out[field] = `\${${env[0]}}`;
|
|
305
|
+
for (const [field, { env, required, placeholder }] of Object.entries(envMap)) {
|
|
306
|
+
if ((required || placeholder) && env[0]) out[field] = `\${${env[0]}}`;
|
|
122
307
|
}
|
|
123
308
|
return out;
|
|
124
309
|
}
|
|
@@ -156,7 +341,7 @@ function buildProviderFromEnv(providerName, projectName) {
|
|
|
156
341
|
throw new UserError(`Unknown provider '${providerName}'. Registered: ${Array.from(registry.keys()).join(", ")}`);
|
|
157
342
|
}
|
|
158
343
|
const config = resolveProviderConfigFromEnv(providerName);
|
|
159
|
-
const parsed = def
|
|
344
|
+
const parsed = parseProviderConfig(def, config);
|
|
160
345
|
const adapter2 = def.createAdapter(parsed, projectName);
|
|
161
346
|
validateProviderFacets(def, adapter2);
|
|
162
347
|
return adapter2;
|
|
@@ -210,169 +395,6 @@ function skillNameFromFiles(files) {
|
|
|
210
395
|
return match?.[1]?.replace(/^["']|["']$/g, "") || void 0;
|
|
211
396
|
}
|
|
212
397
|
|
|
213
|
-
// src/internal/providers/base-client.ts
|
|
214
|
-
var ApiError = class _ApiError extends Error {
|
|
215
|
-
constructor(statusCode, responseBody, prefix) {
|
|
216
|
-
super(`${prefix} ${statusCode}: ${responseBody}`);
|
|
217
|
-
this.statusCode = statusCode;
|
|
218
|
-
this.responseBody = responseBody;
|
|
219
|
-
}
|
|
220
|
-
statusCode;
|
|
221
|
-
responseBody;
|
|
222
|
-
static isNotFound(err) {
|
|
223
|
-
return err instanceof _ApiError && err.statusCode === 404;
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
var ConflictError = class extends ApiError {
|
|
227
|
-
};
|
|
228
|
-
var BaseApiClient = class {
|
|
229
|
-
isConflict(_status, _body) {
|
|
230
|
-
return false;
|
|
231
|
-
}
|
|
232
|
-
async throwIfError(res) {
|
|
233
|
-
if (res.ok) return;
|
|
234
|
-
const body = await res.text();
|
|
235
|
-
if (this.isConflict(res.status, body)) throw new ConflictError(res.status, body, this.errorPrefix);
|
|
236
|
-
throw new ApiError(res.status, body, this.errorPrefix);
|
|
237
|
-
}
|
|
238
|
-
async post(path, body) {
|
|
239
|
-
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
240
|
-
method: "POST",
|
|
241
|
-
headers: this.headers(),
|
|
242
|
-
body: JSON.stringify(body)
|
|
243
|
-
});
|
|
244
|
-
await this.throwIfError(res);
|
|
245
|
-
return res.json();
|
|
246
|
-
}
|
|
247
|
-
async put(path, body) {
|
|
248
|
-
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
249
|
-
method: "PUT",
|
|
250
|
-
headers: this.headers(),
|
|
251
|
-
body: JSON.stringify(body)
|
|
252
|
-
});
|
|
253
|
-
await this.throwIfError(res);
|
|
254
|
-
return res.json();
|
|
255
|
-
}
|
|
256
|
-
async delete(path) {
|
|
257
|
-
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
258
|
-
method: "DELETE",
|
|
259
|
-
headers: this.headers()
|
|
260
|
-
});
|
|
261
|
-
await this.throwIfError(res);
|
|
262
|
-
}
|
|
263
|
-
async get(path) {
|
|
264
|
-
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
265
|
-
method: "GET",
|
|
266
|
-
headers: this.headers()
|
|
267
|
-
});
|
|
268
|
-
await this.throwIfError(res);
|
|
269
|
-
return res.json();
|
|
270
|
-
}
|
|
271
|
-
async getBuffer(path) {
|
|
272
|
-
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
273
|
-
method: "GET",
|
|
274
|
-
headers: this.headers()
|
|
275
|
-
});
|
|
276
|
-
await this.throwIfError(res);
|
|
277
|
-
return Buffer.from(await res.arrayBuffer());
|
|
278
|
-
}
|
|
279
|
-
async *sse(path, options) {
|
|
280
|
-
const controller = new AbortController();
|
|
281
|
-
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
282
|
-
method: "GET",
|
|
283
|
-
headers: { ...this.headers(), Accept: "text/event-stream", ...options?.headers },
|
|
284
|
-
signal: controller.signal
|
|
285
|
-
});
|
|
286
|
-
await this.throwIfError(res);
|
|
287
|
-
const reader = res.body.getReader();
|
|
288
|
-
const decoder = new TextDecoder();
|
|
289
|
-
let buffer = "";
|
|
290
|
-
try {
|
|
291
|
-
while (true) {
|
|
292
|
-
const { done, value } = await reader.read();
|
|
293
|
-
if (done) break;
|
|
294
|
-
buffer += decoder.decode(value, { stream: true });
|
|
295
|
-
let boundary = buffer.indexOf("\n\n");
|
|
296
|
-
while (boundary !== -1) {
|
|
297
|
-
const frame = buffer.slice(0, boundary);
|
|
298
|
-
buffer = buffer.slice(boundary + 2);
|
|
299
|
-
boundary = buffer.indexOf("\n\n");
|
|
300
|
-
const dataLines = [];
|
|
301
|
-
let sseId;
|
|
302
|
-
for (const line of frame.split("\n")) {
|
|
303
|
-
if (line.startsWith(":")) continue;
|
|
304
|
-
if (line.startsWith("event:") && line.slice(6).trim() === "heartbeat") {
|
|
305
|
-
dataLines.length = 0;
|
|
306
|
-
break;
|
|
307
|
-
}
|
|
308
|
-
if (line.startsWith("data:")) {
|
|
309
|
-
dataLines.push(line.slice(5).trimStart());
|
|
310
|
-
}
|
|
311
|
-
if (line.startsWith("id:")) {
|
|
312
|
-
sseId = line.slice(3).trimStart();
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
if (dataLines.length === 0) continue;
|
|
316
|
-
const json = dataLines.join("\n");
|
|
317
|
-
try {
|
|
318
|
-
const parsed = JSON.parse(json);
|
|
319
|
-
if (sseId !== void 0 && parsed.id === void 0) {
|
|
320
|
-
parsed.id = sseId;
|
|
321
|
-
}
|
|
322
|
-
yield parsed;
|
|
323
|
-
} catch {
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
} finally {
|
|
328
|
-
try {
|
|
329
|
-
await reader.cancel();
|
|
330
|
-
} catch {
|
|
331
|
-
}
|
|
332
|
-
controller.abort();
|
|
333
|
-
reader.releaseLock();
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
async postFormData(path, formData) {
|
|
337
|
-
const { "Content-Type": _contentType, ...headers } = this.headers();
|
|
338
|
-
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
339
|
-
method: "POST",
|
|
340
|
-
headers,
|
|
341
|
-
body: formData
|
|
342
|
-
});
|
|
343
|
-
await this.throwIfError(res);
|
|
344
|
-
return res.json();
|
|
345
|
-
}
|
|
346
|
-
async getAllPaged(path) {
|
|
347
|
-
const all = [];
|
|
348
|
-
let cursor;
|
|
349
|
-
for (; ; ) {
|
|
350
|
-
const sep = path.includes("?") ? "&" : "?";
|
|
351
|
-
const param = this.paginationStrategy === "page" ? "page" : "after_id";
|
|
352
|
-
const url = cursor ? `${path}${sep}limit=100&${param}=${encodeURIComponent(cursor)}` : `${path}${sep}limit=100`;
|
|
353
|
-
const res = await this.get(url);
|
|
354
|
-
const data = res.data ?? [];
|
|
355
|
-
all.push(...data);
|
|
356
|
-
if (data.length === 0) break;
|
|
357
|
-
if (this.paginationStrategy === "page") {
|
|
358
|
-
if (!res.next_page) break;
|
|
359
|
-
cursor = res.next_page;
|
|
360
|
-
} else {
|
|
361
|
-
if (!res.has_more || !res.last_id) break;
|
|
362
|
-
cursor = res.last_id;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
return all;
|
|
366
|
-
}
|
|
367
|
-
};
|
|
368
|
-
function toRemoteResource(res) {
|
|
369
|
-
return {
|
|
370
|
-
id: res.id,
|
|
371
|
-
type: res.type,
|
|
372
|
-
version: res.version
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
|
|
376
398
|
// src/internal/providers/memory-api.ts
|
|
377
399
|
function query(path, values) {
|
|
378
400
|
const params = new URLSearchParams();
|
|
@@ -3371,7 +3393,13 @@ var BailianClient = class extends BaseApiClient {
|
|
|
3371
3393
|
constructor(config) {
|
|
3372
3394
|
super();
|
|
3373
3395
|
this.apiKey = config.apiKey;
|
|
3374
|
-
|
|
3396
|
+
if (config.baseUrl) {
|
|
3397
|
+
this.baseUrl = config.baseUrl;
|
|
3398
|
+
} else if (config.workspaceId) {
|
|
3399
|
+
this.baseUrl = `https://${config.workspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/agentstudio`;
|
|
3400
|
+
} else {
|
|
3401
|
+
throw new UserError("bailian provider requires either base_url or workspace_id");
|
|
3402
|
+
}
|
|
3375
3403
|
}
|
|
3376
3404
|
headers() {
|
|
3377
3405
|
return {
|
|
@@ -4271,8 +4299,10 @@ var BAILIAN_CAPABILITIES = {
|
|
|
4271
4299
|
import { z as z3 } from "zod";
|
|
4272
4300
|
var bailianConfigSchema = z3.object({
|
|
4273
4301
|
api_key: z3.string(),
|
|
4274
|
-
workspace_id: z3.string(),
|
|
4302
|
+
workspace_id: z3.string().optional(),
|
|
4275
4303
|
base_url: z3.string().optional()
|
|
4304
|
+
}).refine((config) => Boolean(config.workspace_id || config.base_url), {
|
|
4305
|
+
message: "either workspace_id or base_url is required"
|
|
4276
4306
|
});
|
|
4277
4307
|
|
|
4278
4308
|
// src/internal/providers/bailian/index.ts
|
|
@@ -5956,7 +5986,7 @@ import { readFileSync as readFileSync7, statSync as statSync3 } from "fs";
|
|
|
5956
5986
|
import { dirname as dirname9, resolve as resolve10 } from "path";
|
|
5957
5987
|
async function resolveSkillFiles(decl, ctx) {
|
|
5958
5988
|
if (/^https?:\/\//i.test(decl.source)) {
|
|
5959
|
-
const res = await
|
|
5989
|
+
const res = await resolveFetch()(decl.source);
|
|
5960
5990
|
if (!res.ok) throw new Error(`skill source \u4E0B\u8F7D\u5931\u8D25\uFF1A${res.status} ${decl.source}`);
|
|
5961
5991
|
return extractSkillZipFiles(Buffer.from(await res.arrayBuffer()));
|
|
5962
5992
|
}
|
|
@@ -9136,7 +9166,11 @@ function resolveActiveProvider() {
|
|
|
9136
9166
|
}
|
|
9137
9167
|
function areRuntimeCredentialsReady() {
|
|
9138
9168
|
const provider = resolveActiveProvider();
|
|
9139
|
-
return AGENTS_PROVIDER_FIELDS[provider].every((field) =>
|
|
9169
|
+
return AGENTS_PROVIDER_FIELDS[provider].every((field) => {
|
|
9170
|
+
if (process.env[field.key]?.trim()) return true;
|
|
9171
|
+
if (field.key === "BAILIAN_WORKSPACE_ID") return Boolean(process.env.BAILIAN_BASE_URL?.trim());
|
|
9172
|
+
return false;
|
|
9173
|
+
});
|
|
9140
9174
|
}
|
|
9141
9175
|
function isProvider(value) {
|
|
9142
9176
|
return AGENTS_CONFIG_PROVIDERS.includes(value);
|
|
@@ -9733,9 +9767,11 @@ export {
|
|
|
9733
9767
|
AgentSyncRunSchema,
|
|
9734
9768
|
AgentSyncStatusSchema,
|
|
9735
9769
|
AgentWithReadinessSchema,
|
|
9770
|
+
ApiError,
|
|
9736
9771
|
CloudAgentSchema,
|
|
9737
9772
|
CloudEnvironmentSchema,
|
|
9738
9773
|
CloudVaultSchema,
|
|
9774
|
+
ConflictError,
|
|
9739
9775
|
CreateSessionRequestSchema,
|
|
9740
9776
|
CreateSessionResponseSchema,
|
|
9741
9777
|
DiagnosticSchema,
|
|
@@ -9843,6 +9879,7 @@ export {
|
|
|
9843
9879
|
runDeploymentForContext,
|
|
9844
9880
|
sendSessionMessagePolling,
|
|
9845
9881
|
sendSessionMessageStreaming,
|
|
9882
|
+
setDefaultFetch,
|
|
9846
9883
|
startSessionRun,
|
|
9847
9884
|
startSessionRunPolling,
|
|
9848
9885
|
streamSessionEvents,
|