@openagentpack/playground 0.1.0 → 0.2.0-beta-ddef91c-20260720
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/bin/playground.js +187 -129
- package/package.json +3 -4
- package/web/assets/index.js +47 -47
- package/web/assets/style.css +1 -1
package/dist/bin/playground.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// src/server.ts
|
|
4
4
|
import "@hono/zod-openapi";
|
|
5
5
|
import { readFileSync } from "fs";
|
|
6
|
-
import { dirname as
|
|
6
|
+
import { dirname as dirname3, join as join2 } from "path";
|
|
7
7
|
import { fileURLToPath } from "url";
|
|
8
8
|
import { serve } from "@hono/node-server";
|
|
9
9
|
import { serveStatic } from "@hono/node-server/serve-static";
|
|
@@ -1052,109 +1052,6 @@ function localizedDescription(template) {
|
|
|
1052
1052
|
return names.zh ?? names.en ?? Object.values(names)[0] ?? template.id;
|
|
1053
1053
|
}
|
|
1054
1054
|
|
|
1055
|
-
// ../playbooks/src/session-runtime.ts
|
|
1056
|
-
function playbookIdentityMismatchMessage(playbookId) {
|
|
1057
|
-
return `\u73A9\u6CD5\u300C${playbookId}\u300D\u5B58\u5728\u540C\u5E94\u7528\u540C\u540D Agent\uFF0C\u4F46 metadata.${PLAYBOOK_APP_METADATA_KEY}/${PLAYBOOK_METADATA_KEY} \u672A\u5BF9\u4E0A\uFF0C\u7591\u4F3C\u8EAB\u4EFD\u672A\u76D6\u7AE0\uFF1B\u8BF7\u68C0\u67E5\u914D\u7F6E\u800C\u975E\u91CD\u590D\u521B\u5EFA\u3002`;
|
|
1058
|
-
}
|
|
1059
|
-
var PlaybookAgentIdentityMismatchError = class extends Error {
|
|
1060
|
-
constructor(playbookId) {
|
|
1061
|
-
super(playbookIdentityMismatchMessage(playbookId));
|
|
1062
|
-
this.name = "PlaybookAgentIdentityMismatchError";
|
|
1063
|
-
}
|
|
1064
|
-
};
|
|
1065
|
-
function pickPlaybookAgent(agents, input) {
|
|
1066
|
-
const matched = agents.filter(
|
|
1067
|
-
(agent2) => (input.includeArchived || !isArchived(agent2)) && agent2.metadata?.[PLAYBOOK_APP_METADATA_KEY] === input.appId && agent2.metadata?.[PLAYBOOK_METADATA_KEY] === input.playbookId
|
|
1068
|
-
);
|
|
1069
|
-
if (matched.length <= 1) {
|
|
1070
|
-
return {
|
|
1071
|
-
agent: matched[0],
|
|
1072
|
-
duplicates: [],
|
|
1073
|
-
identityMismatch: matched.length === 0 && hasSameNameCurrentAppAgent(agents, input)
|
|
1074
|
-
};
|
|
1075
|
-
}
|
|
1076
|
-
const sorted = [...matched].sort((a, b) => epochOf(updatedAtOf(b)) - epochOf(updatedAtOf(a)));
|
|
1077
|
-
const [agent, ...duplicates] = sorted;
|
|
1078
|
-
return { agent, duplicates, identityMismatch: false };
|
|
1079
|
-
}
|
|
1080
|
-
function createPlaybookSessionRuntime(adapters) {
|
|
1081
|
-
async function findAgent(playbookId) {
|
|
1082
|
-
const [agents, expectedAgentName] = await Promise.all([
|
|
1083
|
-
adapters.agents.listPlaybookAgents({ playbookId, includeArchived: false }),
|
|
1084
|
-
adapters.identity.expectedAgentName?.(playbookId)
|
|
1085
|
-
]);
|
|
1086
|
-
return pickPlaybookAgent(agents, {
|
|
1087
|
-
playbookId,
|
|
1088
|
-
appId: adapters.identity.appId,
|
|
1089
|
-
expectedAgentName
|
|
1090
|
-
});
|
|
1091
|
-
}
|
|
1092
|
-
return {
|
|
1093
|
-
async list(input) {
|
|
1094
|
-
return adapters.sessions.list(input);
|
|
1095
|
-
},
|
|
1096
|
-
async getDetail(input) {
|
|
1097
|
-
return adapters.sessions.getDetail(input);
|
|
1098
|
-
},
|
|
1099
|
-
async start(input) {
|
|
1100
|
-
const pick = await findAgent(input.playbookId);
|
|
1101
|
-
if (pick.identityMismatch) throw new PlaybookAgentIdentityMismatchError(input.playbookId);
|
|
1102
|
-
if (pick.agent && pick.duplicates.length) {
|
|
1103
|
-
adapters.onDuplicateAgent?.({ playbookId: input.playbookId, winner: pick.agent, duplicates: pick.duplicates });
|
|
1104
|
-
}
|
|
1105
|
-
const agent = await adapters.agents.ensurePlaybookAgent({
|
|
1106
|
-
playbookId: input.playbookId,
|
|
1107
|
-
model: input.model,
|
|
1108
|
-
matched: pick.agent
|
|
1109
|
-
});
|
|
1110
|
-
const started = await adapters.sessions.start({ ...input, remoteAgentId: agent.id });
|
|
1111
|
-
if (started.events) {
|
|
1112
|
-
adapters.events?.attachLiveStream(started.sessionId, started.events, started.completedEvents);
|
|
1113
|
-
} else if (started.completedEvents?.length) {
|
|
1114
|
-
adapters.events?.seedCompleted(started.sessionId, started.completedEvents);
|
|
1115
|
-
}
|
|
1116
|
-
return adapters.sessions.getDetail({
|
|
1117
|
-
sessionId: started.sessionId,
|
|
1118
|
-
playbookId: input.playbookId,
|
|
1119
|
-
remoteAgentId: agent.id
|
|
1120
|
-
});
|
|
1121
|
-
},
|
|
1122
|
-
async send(input) {
|
|
1123
|
-
const sent = await adapters.sessions.send(input);
|
|
1124
|
-
if (sent.events) {
|
|
1125
|
-
adapters.events?.attachLiveStream(sent.sessionId, sent.events, sent.completedEvents);
|
|
1126
|
-
} else if (sent.completedEvents?.length) {
|
|
1127
|
-
adapters.events?.seedCompleted(sent.sessionId, sent.completedEvents);
|
|
1128
|
-
}
|
|
1129
|
-
return adapters.sessions.getDetail({
|
|
1130
|
-
sessionId: sent.sessionId,
|
|
1131
|
-
playbookId: input.playbookId
|
|
1132
|
-
});
|
|
1133
|
-
},
|
|
1134
|
-
async delete(input) {
|
|
1135
|
-
await adapters.sessions.delete(input);
|
|
1136
|
-
}
|
|
1137
|
-
};
|
|
1138
|
-
}
|
|
1139
|
-
function hasSameNameCurrentAppAgent(agents, input) {
|
|
1140
|
-
if (!input.expectedAgentName) return false;
|
|
1141
|
-
return agents.some(
|
|
1142
|
-
(agent) => !isArchived(agent) && agent.metadata?.[PLAYBOOK_APP_METADATA_KEY] === input.appId && agent.name === input.expectedAgentName
|
|
1143
|
-
);
|
|
1144
|
-
}
|
|
1145
|
-
function isArchived(agent) {
|
|
1146
|
-
return agent.archivedAt != null || agent.archived_at != null;
|
|
1147
|
-
}
|
|
1148
|
-
function updatedAtOf(agent) {
|
|
1149
|
-
return agent.updatedAt ?? agent.updated_at;
|
|
1150
|
-
}
|
|
1151
|
-
function epochOf(value) {
|
|
1152
|
-
if (value == null) return 0;
|
|
1153
|
-
if (typeof value === "number") return value;
|
|
1154
|
-
const parsed = Date.parse(value);
|
|
1155
|
-
return Number.isNaN(parsed) ? 0 : parsed;
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1158
1055
|
// ../playbooks/src/index.ts
|
|
1159
1056
|
var PLAYBOOK_SOURCES = {
|
|
1160
1057
|
bailian: bailian_default,
|
|
@@ -1314,7 +1211,7 @@ function compileAgentRuntime(playbookId, baseConfig, modelOverride) {
|
|
|
1314
1211
|
const config = cloneConfig(baseConfig);
|
|
1315
1212
|
const resolved = resolveSeedPlaybook(effectiveId, provider);
|
|
1316
1213
|
const runtimeAgentId = resolved.agent.name;
|
|
1317
|
-
const built = buildAgentDecl(void 0, toAgentBuildInput(resolved, provider, modelOverride));
|
|
1214
|
+
const built = buildAgentDecl(void 0, toAgentBuildInput(resolved, provider, baseConfig, modelOverride));
|
|
1318
1215
|
config.agents = {
|
|
1319
1216
|
...config.agents ?? {},
|
|
1320
1217
|
[runtimeAgentId]: built.agent
|
|
@@ -1373,12 +1270,32 @@ function validateAgent(playbookId, _config) {
|
|
|
1373
1270
|
function computeAgentConfigHash(config, agentId) {
|
|
1374
1271
|
return createHash("sha256").update(stableStringify({ agentId, config })).digest("hex").slice(0, 16);
|
|
1375
1272
|
}
|
|
1376
|
-
function toAgentBuildInput(resolved, provider, modelOverride) {
|
|
1273
|
+
function toAgentBuildInput(resolved, provider, baseConfig, modelOverride) {
|
|
1377
1274
|
const model = resolvePlaybookModel(resolved, provider, modelOverride);
|
|
1275
|
+
const envKeys = Object.keys(baseConfig.environments ?? {});
|
|
1276
|
+
if (envKeys.length !== 1) {
|
|
1277
|
+
throw new Error(
|
|
1278
|
+
`Expected exactly 1 environment in runtime config, got ${envKeys.length}. The agent compile path assumes a single base environment per provider.`
|
|
1279
|
+
);
|
|
1280
|
+
}
|
|
1281
|
+
const environmentName = envKeys[0];
|
|
1282
|
+
const vaultProfile = getVaultProfile(provider);
|
|
1283
|
+
let vaultName;
|
|
1284
|
+
if (vaultProfile) {
|
|
1285
|
+
const vaultKeys = Object.keys(baseConfig.vaults ?? {});
|
|
1286
|
+
if (vaultKeys.length !== 1) {
|
|
1287
|
+
throw new Error(
|
|
1288
|
+
`Expected exactly 1 vault in runtime config for provider '${provider}', got ${vaultKeys.length}. The agent compile path assumes a single base vault per provider.`
|
|
1289
|
+
);
|
|
1290
|
+
}
|
|
1291
|
+
vaultName = vaultKeys[0];
|
|
1292
|
+
}
|
|
1378
1293
|
return {
|
|
1379
1294
|
description: resolved.agent.description,
|
|
1380
1295
|
model,
|
|
1381
1296
|
instructions: resolved.agent.system,
|
|
1297
|
+
environment: environmentName,
|
|
1298
|
+
vault: vaultName,
|
|
1382
1299
|
provider,
|
|
1383
1300
|
builtinTools: resolved.agent.builtinTools,
|
|
1384
1301
|
skills: resolved.agent.skills.map(
|
|
@@ -1458,13 +1375,15 @@ async function buildRuntimeConfig() {
|
|
|
1458
1375
|
// Secret value is injected from env here — never stored in playbooks.
|
|
1459
1376
|
secret_value: requireEnv(cred.secret_name),
|
|
1460
1377
|
...cred.networking ? { networking: cred.networking } : {}
|
|
1461
|
-
}))
|
|
1378
|
+
})),
|
|
1379
|
+
metadata: { "agents.vault": "true" }
|
|
1462
1380
|
}
|
|
1463
1381
|
} : {};
|
|
1464
1382
|
const environments = {
|
|
1465
1383
|
[environment.name]: {
|
|
1466
1384
|
...environment.description ? { description: environment.description } : {},
|
|
1467
|
-
config: environment.config
|
|
1385
|
+
config: environment.config,
|
|
1386
|
+
metadata: { "agents.base": "true" }
|
|
1468
1387
|
}
|
|
1469
1388
|
};
|
|
1470
1389
|
const rawConfig = {
|
|
@@ -1489,12 +1408,47 @@ function requireEnv(name) {
|
|
|
1489
1408
|
}
|
|
1490
1409
|
|
|
1491
1410
|
// ../../apps/server/src/lib/state-scope.ts
|
|
1492
|
-
import {
|
|
1411
|
+
import { copyFileSync, existsSync, mkdirSync, renameSync } from "fs";
|
|
1412
|
+
import { homedir } from "os";
|
|
1413
|
+
import { dirname, join, resolve } from "path";
|
|
1493
1414
|
import { LocalFileStateBackend } from "@openagentpack/sdk";
|
|
1494
|
-
var DEFAULT_STATE_PATH = "
|
|
1415
|
+
var DEFAULT_STATE_PATH = join(homedir(), ".agents", "playground.state.json");
|
|
1416
|
+
var LEGACY_STATE_PATH = "examples/bailian/bailian-cli/agents.state.json";
|
|
1417
|
+
var migrationChecked = false;
|
|
1418
|
+
function ensureMigrated(newPath, cwd) {
|
|
1419
|
+
if (migrationChecked) return;
|
|
1420
|
+
if (existsSync(newPath)) {
|
|
1421
|
+
migrationChecked = true;
|
|
1422
|
+
return;
|
|
1423
|
+
}
|
|
1424
|
+
const legacyPath = resolve(cwd, LEGACY_STATE_PATH);
|
|
1425
|
+
if (!existsSync(legacyPath)) {
|
|
1426
|
+
migrationChecked = true;
|
|
1427
|
+
return;
|
|
1428
|
+
}
|
|
1429
|
+
try {
|
|
1430
|
+
mkdirSync(dirname(newPath), { recursive: true });
|
|
1431
|
+
copyFileSync(legacyPath, newPath);
|
|
1432
|
+
try {
|
|
1433
|
+
renameSync(legacyPath, `${legacyPath}.migrated`);
|
|
1434
|
+
} catch {
|
|
1435
|
+
}
|
|
1436
|
+
migrationChecked = true;
|
|
1437
|
+
console.warn(
|
|
1438
|
+
`[state] Migrated playground state from legacy path:
|
|
1439
|
+
${legacyPath}
|
|
1440
|
+
\u2192 ${newPath}
|
|
1441
|
+
The legacy file has been renamed to ${legacyPath}.migrated.`
|
|
1442
|
+
);
|
|
1443
|
+
} catch (error) {
|
|
1444
|
+
console.warn(`[state] Failed to migrate legacy state file: ${error instanceof Error ? error.message : error}`);
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1495
1447
|
function resolveStatePath(env = process.env, cwd = process.cwd()) {
|
|
1496
1448
|
const configured = env.AGENTS_STATE_PATH?.trim();
|
|
1497
|
-
|
|
1449
|
+
if (configured) return resolve(cwd, configured);
|
|
1450
|
+
ensureMigrated(DEFAULT_STATE_PATH, cwd);
|
|
1451
|
+
return DEFAULT_STATE_PATH;
|
|
1498
1452
|
}
|
|
1499
1453
|
function deriveWebUiStateScope() {
|
|
1500
1454
|
return { projectId: RUNTIME_PROJECT_NAME };
|
|
@@ -1633,6 +1587,109 @@ async function importMatchedCloudAgent(input, provider, matched) {
|
|
|
1633
1587
|
});
|
|
1634
1588
|
}
|
|
1635
1589
|
|
|
1590
|
+
// ../../apps/server/src/services/sessions/playbook-session-adapter/runtime.ts
|
|
1591
|
+
function playbookIdentityMismatchMessage(playbookId) {
|
|
1592
|
+
return `\u73A9\u6CD5\u300C${playbookId}\u300D\u5B58\u5728\u540C\u5E94\u7528\u540C\u540D Agent\uFF0C\u4F46 metadata.${PLAYBOOK_APP_METADATA_KEY}/${PLAYBOOK_METADATA_KEY} \u672A\u5BF9\u4E0A\uFF0C\u7591\u4F3C\u8EAB\u4EFD\u672A\u76D6\u7AE0\uFF1B\u8BF7\u68C0\u67E5\u914D\u7F6E\u800C\u975E\u91CD\u590D\u521B\u5EFA\u3002`;
|
|
1593
|
+
}
|
|
1594
|
+
var PlaybookAgentIdentityMismatchError = class extends Error {
|
|
1595
|
+
constructor(playbookId) {
|
|
1596
|
+
super(playbookIdentityMismatchMessage(playbookId));
|
|
1597
|
+
this.name = "PlaybookAgentIdentityMismatchError";
|
|
1598
|
+
}
|
|
1599
|
+
};
|
|
1600
|
+
function pickPlaybookAgent(agents, input) {
|
|
1601
|
+
const matched = agents.filter(
|
|
1602
|
+
(agent2) => (input.includeArchived || !isArchived(agent2)) && agent2.metadata?.[PLAYBOOK_APP_METADATA_KEY] === input.appId && agent2.metadata?.[PLAYBOOK_METADATA_KEY] === input.playbookId
|
|
1603
|
+
);
|
|
1604
|
+
if (matched.length <= 1) {
|
|
1605
|
+
return {
|
|
1606
|
+
agent: matched[0],
|
|
1607
|
+
duplicates: [],
|
|
1608
|
+
identityMismatch: matched.length === 0 && hasSameNameCurrentAppAgent(agents, input)
|
|
1609
|
+
};
|
|
1610
|
+
}
|
|
1611
|
+
const sorted = [...matched].sort((a, b) => epochOf(updatedAtOf(b)) - epochOf(updatedAtOf(a)));
|
|
1612
|
+
const [agent, ...duplicates] = sorted;
|
|
1613
|
+
return { agent, duplicates, identityMismatch: false };
|
|
1614
|
+
}
|
|
1615
|
+
function createPlaybookSessionRuntime(deps) {
|
|
1616
|
+
async function findAgent(playbookId) {
|
|
1617
|
+
const [agents, expectedAgentName] = await Promise.all([
|
|
1618
|
+
deps.agents.listPlaybookAgents({ playbookId, includeArchived: false }),
|
|
1619
|
+
deps.identity.expectedAgentName?.(playbookId)
|
|
1620
|
+
]);
|
|
1621
|
+
return pickPlaybookAgent(agents, {
|
|
1622
|
+
playbookId,
|
|
1623
|
+
appId: deps.identity.appId,
|
|
1624
|
+
expectedAgentName
|
|
1625
|
+
});
|
|
1626
|
+
}
|
|
1627
|
+
return {
|
|
1628
|
+
async list(input) {
|
|
1629
|
+
return deps.sessions.list(input);
|
|
1630
|
+
},
|
|
1631
|
+
async getDetail(input) {
|
|
1632
|
+
return deps.sessions.getDetail(input);
|
|
1633
|
+
},
|
|
1634
|
+
async start(input) {
|
|
1635
|
+
const pick = await findAgent(input.playbookId);
|
|
1636
|
+
if (pick.identityMismatch) throw new PlaybookAgentIdentityMismatchError(input.playbookId);
|
|
1637
|
+
if (pick.agent && pick.duplicates.length) {
|
|
1638
|
+
deps.onDuplicateAgent?.({ playbookId: input.playbookId, winner: pick.agent, duplicates: pick.duplicates });
|
|
1639
|
+
}
|
|
1640
|
+
const agent = await deps.agents.ensurePlaybookAgent({
|
|
1641
|
+
playbookId: input.playbookId,
|
|
1642
|
+
model: input.model,
|
|
1643
|
+
matched: pick.agent
|
|
1644
|
+
});
|
|
1645
|
+
const started = await deps.sessions.start({ ...input, remoteAgentId: agent.id });
|
|
1646
|
+
if (started.events) {
|
|
1647
|
+
deps.events?.attachLiveStream(started.sessionId, started.events, started.completedEvents);
|
|
1648
|
+
} else if (started.completedEvents?.length) {
|
|
1649
|
+
deps.events?.seedCompleted(started.sessionId, started.completedEvents);
|
|
1650
|
+
}
|
|
1651
|
+
return deps.sessions.getDetail({
|
|
1652
|
+
sessionId: started.sessionId,
|
|
1653
|
+
playbookId: input.playbookId,
|
|
1654
|
+
remoteAgentId: agent.id
|
|
1655
|
+
});
|
|
1656
|
+
},
|
|
1657
|
+
async send(input) {
|
|
1658
|
+
const sent = await deps.sessions.send(input);
|
|
1659
|
+
if (sent.events) {
|
|
1660
|
+
deps.events?.attachLiveStream(sent.sessionId, sent.events, sent.completedEvents);
|
|
1661
|
+
} else if (sent.completedEvents?.length) {
|
|
1662
|
+
deps.events?.seedCompleted(sent.sessionId, sent.completedEvents);
|
|
1663
|
+
}
|
|
1664
|
+
return deps.sessions.getDetail({
|
|
1665
|
+
sessionId: sent.sessionId,
|
|
1666
|
+
playbookId: input.playbookId
|
|
1667
|
+
});
|
|
1668
|
+
},
|
|
1669
|
+
async delete(input) {
|
|
1670
|
+
await deps.sessions.delete(input);
|
|
1671
|
+
}
|
|
1672
|
+
};
|
|
1673
|
+
}
|
|
1674
|
+
function hasSameNameCurrentAppAgent(agents, input) {
|
|
1675
|
+
if (!input.expectedAgentName) return false;
|
|
1676
|
+
return agents.some(
|
|
1677
|
+
(agent) => !isArchived(agent) && agent.metadata?.[PLAYBOOK_APP_METADATA_KEY] === input.appId && agent.name === input.expectedAgentName
|
|
1678
|
+
);
|
|
1679
|
+
}
|
|
1680
|
+
function isArchived(agent) {
|
|
1681
|
+
return agent.archivedAt != null || agent.archived_at != null;
|
|
1682
|
+
}
|
|
1683
|
+
function updatedAtOf(agent) {
|
|
1684
|
+
return agent.updatedAt ?? agent.updated_at;
|
|
1685
|
+
}
|
|
1686
|
+
function epochOf(value) {
|
|
1687
|
+
if (value == null) return 0;
|
|
1688
|
+
if (typeof value === "number") return value;
|
|
1689
|
+
const parsed = Date.parse(value);
|
|
1690
|
+
return Number.isNaN(parsed) ? 0 : parsed;
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1636
1693
|
// ../../apps/server/src/services/sessions/playbook-session-adapter/sessions.ts
|
|
1637
1694
|
import {
|
|
1638
1695
|
deleteSession,
|
|
@@ -1838,7 +1895,7 @@ function seedCompletedEvents(sessionId, events) {
|
|
|
1838
1895
|
}
|
|
1839
1896
|
|
|
1840
1897
|
// ../../apps/server/src/services/sessions/playbook-session-adapter/index.ts
|
|
1841
|
-
function
|
|
1898
|
+
function createServerPlaybookSessionRuntime() {
|
|
1842
1899
|
return createPlaybookSessionRuntime({
|
|
1843
1900
|
identity: {
|
|
1844
1901
|
appId: getPlaybookAppId(),
|
|
@@ -1898,7 +1955,7 @@ function createModeAPlaybookSessionRuntime() {
|
|
|
1898
1955
|
onDuplicateAgent({ playbookId, winner, duplicates }) {
|
|
1899
1956
|
const all = [winner, ...duplicates];
|
|
1900
1957
|
console.warn(
|
|
1901
|
-
`\u73A9\u6CD5\u300C${playbookId}\u300D\u5339\u914D\u5230 ${all.length} \u4E2A active playbook Agent(${all.map((agent) => agent.id).join(", ")})
|
|
1958
|
+
`\u73A9\u6CD5\u300C${playbookId}\u300D\u5339\u914D\u5230 ${all.length} \u4E2A active playbook Agent(${all.map((agent) => agent.id).join(", ")})\uFF1B\u53D6\u6700\u8FD1\u66F4\u65B0\u7684 ${winner.id}\u3002`
|
|
1902
1959
|
);
|
|
1903
1960
|
}
|
|
1904
1961
|
});
|
|
@@ -1918,7 +1975,7 @@ async function updatePlaybookAgentModel(slug, model) {
|
|
|
1918
1975
|
throw new UserError2(run.error ?? `Failed to update agent '${input.agentId}' model (status: ${run.status}).`);
|
|
1919
1976
|
}
|
|
1920
1977
|
}
|
|
1921
|
-
var playbookSessionRuntime =
|
|
1978
|
+
var playbookSessionRuntime = createServerPlaybookSessionRuntime();
|
|
1922
1979
|
async function listSessionsForAgent(input) {
|
|
1923
1980
|
const requestedAgentId = input.agentId?.trim() || void 0;
|
|
1924
1981
|
const limit = input.limit ?? 50;
|
|
@@ -2089,7 +2146,7 @@ import { areRuntimeCredentialsReady, resolveActiveProvider as resolveActiveProvi
|
|
|
2089
2146
|
|
|
2090
2147
|
// ../../apps/server/src/lib/agents-config.ts
|
|
2091
2148
|
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
2092
|
-
import { dirname } from "path";
|
|
2149
|
+
import { dirname as dirname2 } from "path";
|
|
2093
2150
|
import {
|
|
2094
2151
|
AGENTS_CONFIG_PROVIDERS,
|
|
2095
2152
|
AGENTS_PROVIDER_FIELDS,
|
|
@@ -2168,17 +2225,20 @@ async function readProviderConfig() {
|
|
|
2168
2225
|
}
|
|
2169
2226
|
const provider = diskConfig.AGENTS_PROVIDER ?? resolveActiveProvider();
|
|
2170
2227
|
const merged = { AGENTS_PROVIDER: provider };
|
|
2171
|
-
for (const
|
|
2172
|
-
const
|
|
2173
|
-
|
|
2174
|
-
|
|
2228
|
+
for (const candidateProvider of AGENTS_CONFIG_PROVIDERS) {
|
|
2229
|
+
for (const field of AGENTS_PROVIDER_FIELDS[candidateProvider]) {
|
|
2230
|
+
const diskValue = diskConfig[field.key]?.trim();
|
|
2231
|
+
const envValue = process.env[field.key]?.trim();
|
|
2232
|
+
const value = diskValue || envValue;
|
|
2233
|
+
if (value) merged[field.key] = value;
|
|
2234
|
+
}
|
|
2175
2235
|
}
|
|
2176
2236
|
return merged;
|
|
2177
2237
|
}
|
|
2178
2238
|
async function writeProviderConfig(input) {
|
|
2179
2239
|
const config = validateProviderConfig(input);
|
|
2180
2240
|
const path = providerConfigPath();
|
|
2181
|
-
await mkdir(
|
|
2241
|
+
await mkdir(dirname2(path), { recursive: true });
|
|
2182
2242
|
const payload = { AGENTS_PROVIDER: config.AGENTS_PROVIDER };
|
|
2183
2243
|
for (const field of AGENTS_PROVIDER_FIELDS[config.AGENTS_PROVIDER]) {
|
|
2184
2244
|
payload[field.key] = config[field.key];
|
|
@@ -2668,8 +2728,7 @@ var SessionParamsSchema = z7.object({
|
|
|
2668
2728
|
var CreateSessionBodySchema = z7.object({
|
|
2669
2729
|
agentId: z7.string(),
|
|
2670
2730
|
prompt: z7.string().min(1),
|
|
2671
|
-
// Required: a session must be pinned to a cloud environment (sandbox).
|
|
2672
|
-
// enforce this so Mode A (REST/OpenAPI) and Mode B (console) reject env-less creates.
|
|
2731
|
+
// Required: a session must be pinned to a cloud environment (sandbox).
|
|
2673
2732
|
environmentId: z7.string().min(1),
|
|
2674
2733
|
// Optional: cloud vault ids to bind a user-supplied credential so the sandbox receives it.
|
|
2675
2734
|
// Top-level binding shape matches the console createSession.
|
|
@@ -3347,9 +3406,8 @@ var CloudVaultsResponseSchema = z10.object({
|
|
|
3347
3406
|
var CreateVaultBodySchema = z10.object({
|
|
3348
3407
|
name: z10.string().min(1),
|
|
3349
3408
|
metadata: z10.record(z10.string(), z10.string()).optional(),
|
|
3350
|
-
// The DASHSCOPE_API_KEY stored as the vault's credential secret value. Optional:
|
|
3351
|
-
//
|
|
3352
|
-
// DASHSCOPE_API_KEY env. (Mode B never reaches this REST route — it goes via console RPC.)
|
|
3409
|
+
// The DASHSCOPE_API_KEY stored as the vault's credential secret value. Optional:
|
|
3410
|
+
// when omitted the server injects it from its own DASHSCOPE_API_KEY env.
|
|
3353
3411
|
key: z10.string().min(1).optional()
|
|
3354
3412
|
});
|
|
3355
3413
|
var CreateVaultResponseSchema = z10.object({
|
|
@@ -3410,8 +3468,8 @@ vaultsRoute.openapi(createVaultRoute, async (c) => {
|
|
|
3410
3468
|
const vault = await withAgentRuntime(
|
|
3411
3469
|
DEFAULT_AGENT_ID,
|
|
3412
3470
|
(ctx) => createCloudVault(ctx, name, {
|
|
3413
|
-
// display_name
|
|
3414
|
-
//
|
|
3471
|
+
// display_name is used as the vault's human-readable label on the provider.
|
|
3472
|
+
// findBaseVault identifies the managed vault by its metadata stamp (agents.vault).
|
|
3415
3473
|
display_name: name,
|
|
3416
3474
|
metadata,
|
|
3417
3475
|
credentials: structure.credentials.map((cred) => ({
|
|
@@ -3511,8 +3569,8 @@ async function resolveListenPort(preferred, maxAttempts = MAX_PORT_ATTEMPTS) {
|
|
|
3511
3569
|
|
|
3512
3570
|
// src/server.ts
|
|
3513
3571
|
var DEFAULT_PLAYGROUND_PORT = 4848;
|
|
3514
|
-
var webRoot =
|
|
3515
|
-
var indexHtml = injectPlaygroundRuntimeMarker(readFileSync(
|
|
3572
|
+
var webRoot = join2(dirname3(fileURLToPath(import.meta.url)), "../../web");
|
|
3573
|
+
var indexHtml = injectPlaygroundRuntimeMarker(readFileSync(join2(webRoot, "index.html"), "utf8"));
|
|
3516
3574
|
function injectPlaygroundRuntimeMarker(html) {
|
|
3517
3575
|
if (html.includes('name="agents-runtime"')) return html;
|
|
3518
3576
|
return html.replace("<head>", '<head>\n <meta name="agents-runtime" content="playground" />');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openagentpack/playground",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-beta-ddef91c-20260720",
|
|
4
4
|
"description": "OpenAgentPack Playground — one-command local web UI for OpenAgentPack",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|
|
@@ -42,14 +42,13 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@hono/node-server": "^1.19.0",
|
|
44
44
|
"@hono/zod-openapi": "^1.4.0",
|
|
45
|
-
"@openagentpack/sdk": "0.
|
|
45
|
+
"@openagentpack/sdk": "0.2.0-beta-ddef91c-20260720",
|
|
46
46
|
"hono": "^4.12.28",
|
|
47
47
|
"zod": "^4.4.3"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/bun": "^1.3.14",
|
|
51
|
-
"@openagentpack/
|
|
52
|
-
"@openagentpack/server": "0.0.3",
|
|
51
|
+
"@openagentpack/server": "0.0.5",
|
|
53
52
|
"@types/node": "^25.9.3",
|
|
54
53
|
"tsup": "^8.5.1",
|
|
55
54
|
"typescript": "^6.0.3"
|