@standardagents/builder 0.39.1 → 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/built-in-routes.js +494 -78
- package/dist/built-in-routes.js.map +1 -1
- package/dist/client/{ApiKeysView-AH5i-H6j.js → ApiKeysView-DoYvZZ7e.js} +1 -1
- package/dist/client/{CenteredContentView-DaBp0K-A.js → CenteredContentView-53PY0cqY.js} +1 -1
- package/dist/client/{CompositionView-yY1Q4M23.js → CompositionView-fp-0YnPt.js} +1 -1
- package/dist/client/{ConfirmDialog.vue_vue_type_script_setup_true_lang-Bwo5CJzF.js → ConfirmDialog.vue_vue_type_script_setup_true_lang-Cvcagja2.js} +1 -1
- package/dist/client/{CopyButton.vue_vue_type_script_setup_true_lang-D0WYwWyA.js → CopyButton.vue_vue_type_script_setup_true_lang-jYvO2v1K.js} +1 -1
- package/dist/client/{DataTable.vue_vue_type_script_setup_true_lang-1wwPn2aY.js → DataTable.vue_vue_type_script_setup_true_lang-DQ3Ufa7y.js} +1 -1
- package/dist/client/{JsonViewer-Bi8Zdmir.js → JsonViewer-6aaGzutE.js} +1 -1
- package/dist/client/{LoginView-BIKahEU6.js → LoginView-DwpCmNw9.js} +1 -1
- package/dist/client/{MarketplaceView-DPDPVH68.js → MarketplaceView-Da02L0J5.js} +1 -1
- package/dist/client/{Modal.vue_vue_type_script_setup_true_lang-D1_rfOsy.js → Modal.vue_vue_type_script_setup_true_lang-Bi8OjiBf.js} +1 -1
- package/dist/client/{ModelModal.vue_vue_type_script_setup_true_lang-DSLeOdxr.js → ModelModal.vue_vue_type_script_setup_true_lang-cYZLOYY7.js} +1 -1
- package/dist/client/{ModelsView-Q2WXu1Gw.js → ModelsView-BLlHO9Ud.js} +1 -1
- package/dist/client/{PromptEditView-BzA-3n1w.js → PromptEditView-EeNwTDtT.js} +1 -1
- package/dist/client/{PromptModal-CJWh_cru.js → PromptModal-BkwrKJ2d.js} +1 -1
- package/dist/client/{PromptsView-BezNl-Et.js → PromptsView-D1r7tsLu.js} +1 -1
- package/dist/client/{ProvidersView-BuzSKxuT.js → ProvidersView-CmUDl5nM.js} +1 -1
- package/dist/client/{ThreadInspectorPane.vue_vue_type_script_setup_true_lang-DOxNp_3C.js → ThreadInspectorPane.vue_vue_type_script_setup_true_lang-cRs3tApQ.js} +1 -1
- package/dist/client/{ThreadsView-DPCpZA4J.js → ThreadsView-Bl5fSIO1.js} +1 -1
- package/dist/client/{ToolsView-DMjFMAhH.js → ToolsView-DlVEF8-7.js} +1 -1
- package/dist/client/{UsersView-B7jXLNQs.js → UsersView-CGlA7a7R.js} +1 -1
- package/dist/client/{VariablesView-CF7x0G8g.js → VariablesView-BpYmJL4V.js} +1 -1
- package/dist/client/index-CKtIkI0N.js +6 -0
- package/dist/client/index.html +1 -1
- package/dist/{discovery-DiMJWisl.d.ts → discovery-DZ7fv-b4.d.ts} +3 -2
- package/dist/{index-yIcqf7DC.d.ts → index-9MaIifn3.d.ts} +7 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1242 -762
- package/dist/index.js.map +1 -1
- package/dist/packing.d.ts +5 -3
- package/dist/packing.js +180 -5
- package/dist/packing.js.map +1 -1
- package/dist/plugin.js +252 -17
- package/dist/plugin.js.map +1 -1
- package/dist/runtime.d.ts +10 -5
- package/dist/runtime.js +993 -750
- package/dist/runtime.js.map +1 -1
- package/dist/test.d.ts +2 -2
- package/dist/{types-Bpe7IANZ.d.ts → types-BMnBYNwn.d.ts} +3 -1
- package/package.json +5 -5
- package/dist/client/index-eGECJFYe.js +0 -6
package/dist/index.js
CHANGED
|
@@ -6809,6 +6809,547 @@ var init_context = __esm({
|
|
|
6809
6809
|
}
|
|
6810
6810
|
});
|
|
6811
6811
|
|
|
6812
|
+
// src/packing/resolver.ts
|
|
6813
|
+
function parseQualifiedName(name) {
|
|
6814
|
+
if (name.startsWith("@")) {
|
|
6815
|
+
const firstSlash = name.indexOf("/");
|
|
6816
|
+
if (firstSlash === -1) {
|
|
6817
|
+
return [null, name];
|
|
6818
|
+
}
|
|
6819
|
+
const secondSlash = name.indexOf("/", firstSlash + 1);
|
|
6820
|
+
if (secondSlash === -1) {
|
|
6821
|
+
return [null, name];
|
|
6822
|
+
}
|
|
6823
|
+
return [name.substring(0, secondSlash), name.substring(secondSlash + 1)];
|
|
6824
|
+
}
|
|
6825
|
+
const separatorIndex = name.indexOf("/");
|
|
6826
|
+
if (separatorIndex === -1) {
|
|
6827
|
+
return [null, name];
|
|
6828
|
+
}
|
|
6829
|
+
return [name.substring(0, separatorIndex), name.substring(separatorIndex + 1)];
|
|
6830
|
+
}
|
|
6831
|
+
function qualifyName(packageId, shortName) {
|
|
6832
|
+
return `${packageId}/${shortName}`;
|
|
6833
|
+
}
|
|
6834
|
+
function getShortName(name) {
|
|
6835
|
+
const [, shortName] = parseQualifiedName(name);
|
|
6836
|
+
return shortName;
|
|
6837
|
+
}
|
|
6838
|
+
function resolveTool(registry, name, namespace) {
|
|
6839
|
+
const [pkgId, shortName] = parseQualifiedName(name);
|
|
6840
|
+
if (pkgId !== null) {
|
|
6841
|
+
const pkg = registry.packages[pkgId];
|
|
6842
|
+
if (!pkg) {
|
|
6843
|
+
throw new NamespaceResolutionError(
|
|
6844
|
+
"tool",
|
|
6845
|
+
name,
|
|
6846
|
+
namespace,
|
|
6847
|
+
`Package "${pkgId}" not found`
|
|
6848
|
+
);
|
|
6849
|
+
}
|
|
6850
|
+
throw new NamespaceResolutionError(
|
|
6851
|
+
"tool",
|
|
6852
|
+
name,
|
|
6853
|
+
namespace,
|
|
6854
|
+
`Cannot access tool "${shortName}" from package "${pkgId}". Only entry point agents are accessible cross-package.`
|
|
6855
|
+
);
|
|
6856
|
+
}
|
|
6857
|
+
if (namespace.type === "packed") {
|
|
6858
|
+
const pkg = registry.packages[namespace.packageId];
|
|
6859
|
+
if (!pkg) {
|
|
6860
|
+
throw new NamespaceResolutionError(
|
|
6861
|
+
"tool",
|
|
6862
|
+
name,
|
|
6863
|
+
namespace,
|
|
6864
|
+
`Package "${namespace.packageId}" not found`
|
|
6865
|
+
);
|
|
6866
|
+
}
|
|
6867
|
+
const loader2 = pkg.tools[shortName];
|
|
6868
|
+
if (!loader2) {
|
|
6869
|
+
throw new NamespaceResolutionError(
|
|
6870
|
+
"tool",
|
|
6871
|
+
name,
|
|
6872
|
+
namespace,
|
|
6873
|
+
`Tool "${shortName}" not found in package "${namespace.packageId}"`
|
|
6874
|
+
);
|
|
6875
|
+
}
|
|
6876
|
+
return loader2;
|
|
6877
|
+
}
|
|
6878
|
+
const loader = registry.global.tools[shortName];
|
|
6879
|
+
if (!loader) {
|
|
6880
|
+
throw new NamespaceResolutionError(
|
|
6881
|
+
"tool",
|
|
6882
|
+
name,
|
|
6883
|
+
namespace,
|
|
6884
|
+
`Tool "${shortName}" not found in global namespace`
|
|
6885
|
+
);
|
|
6886
|
+
}
|
|
6887
|
+
return loader;
|
|
6888
|
+
}
|
|
6889
|
+
function resolvePrompt(registry, name, namespace) {
|
|
6890
|
+
const [pkgId, shortName] = parseQualifiedName(name);
|
|
6891
|
+
if (pkgId !== null) {
|
|
6892
|
+
throw new NamespaceResolutionError(
|
|
6893
|
+
"prompt",
|
|
6894
|
+
name,
|
|
6895
|
+
namespace,
|
|
6896
|
+
`Cannot access prompt "${shortName}" from package "${pkgId}". Prompts are package-internal.`
|
|
6897
|
+
);
|
|
6898
|
+
}
|
|
6899
|
+
if (namespace.type === "packed") {
|
|
6900
|
+
const pkg = registry.packages[namespace.packageId];
|
|
6901
|
+
if (!pkg) {
|
|
6902
|
+
throw new NamespaceResolutionError(
|
|
6903
|
+
"prompt",
|
|
6904
|
+
name,
|
|
6905
|
+
namespace,
|
|
6906
|
+
`Package "${namespace.packageId}" not found`
|
|
6907
|
+
);
|
|
6908
|
+
}
|
|
6909
|
+
const loader2 = pkg.prompts[shortName];
|
|
6910
|
+
if (!loader2) {
|
|
6911
|
+
throw new NamespaceResolutionError(
|
|
6912
|
+
"prompt",
|
|
6913
|
+
name,
|
|
6914
|
+
namespace,
|
|
6915
|
+
`Prompt "${shortName}" not found in package "${namespace.packageId}"`
|
|
6916
|
+
);
|
|
6917
|
+
}
|
|
6918
|
+
return loader2;
|
|
6919
|
+
}
|
|
6920
|
+
const loader = registry.global.prompts[shortName];
|
|
6921
|
+
if (!loader) {
|
|
6922
|
+
throw new NamespaceResolutionError(
|
|
6923
|
+
"prompt",
|
|
6924
|
+
name,
|
|
6925
|
+
namespace,
|
|
6926
|
+
`Prompt "${shortName}" not found in global namespace`
|
|
6927
|
+
);
|
|
6928
|
+
}
|
|
6929
|
+
return loader;
|
|
6930
|
+
}
|
|
6931
|
+
function resolveModel(registry, name, namespace) {
|
|
6932
|
+
const [possiblePkgId, shortName] = parseQualifiedName(name);
|
|
6933
|
+
if (possiblePkgId !== null && registry.packages[possiblePkgId]) {
|
|
6934
|
+
throw new NamespaceResolutionError(
|
|
6935
|
+
"model",
|
|
6936
|
+
name,
|
|
6937
|
+
namespace,
|
|
6938
|
+
`Cannot use qualified model name "${name}". Models must be unqualified. If this is a provider model name, ensure no package named "${possiblePkgId}" exists.`
|
|
6939
|
+
);
|
|
6940
|
+
}
|
|
6941
|
+
const lookupName = name;
|
|
6942
|
+
if (namespace.type === "packed") {
|
|
6943
|
+
const pkg = registry.packages[namespace.packageId];
|
|
6944
|
+
if (pkg) {
|
|
6945
|
+
const loader2 = pkg.models[lookupName];
|
|
6946
|
+
if (loader2) {
|
|
6947
|
+
return loader2;
|
|
6948
|
+
}
|
|
6949
|
+
}
|
|
6950
|
+
const globalLoader = registry.global.models[lookupName];
|
|
6951
|
+
if (globalLoader) {
|
|
6952
|
+
return globalLoader;
|
|
6953
|
+
}
|
|
6954
|
+
throw new NamespaceResolutionError(
|
|
6955
|
+
"model",
|
|
6956
|
+
name,
|
|
6957
|
+
namespace,
|
|
6958
|
+
`Model "${lookupName}" not found in package "${namespace.packageId}" or global namespace`
|
|
6959
|
+
);
|
|
6960
|
+
}
|
|
6961
|
+
const loader = registry.global.models[lookupName];
|
|
6962
|
+
if (!loader) {
|
|
6963
|
+
throw new NamespaceResolutionError(
|
|
6964
|
+
"model",
|
|
6965
|
+
name,
|
|
6966
|
+
namespace,
|
|
6967
|
+
`Model "${lookupName}" not found in global namespace`
|
|
6968
|
+
);
|
|
6969
|
+
}
|
|
6970
|
+
return loader;
|
|
6971
|
+
}
|
|
6972
|
+
function resolveAgent(registry, name, namespace) {
|
|
6973
|
+
const [pkgId, shortName] = parseQualifiedName(name);
|
|
6974
|
+
if (pkgId !== null) {
|
|
6975
|
+
const pkg = registry.packages[pkgId];
|
|
6976
|
+
if (!pkg) {
|
|
6977
|
+
throw new NamespaceResolutionError(
|
|
6978
|
+
"agent",
|
|
6979
|
+
name,
|
|
6980
|
+
namespace,
|
|
6981
|
+
`Package "${pkgId}" not found`
|
|
6982
|
+
);
|
|
6983
|
+
}
|
|
6984
|
+
if (!pkg.entryAgents.includes(shortName)) {
|
|
6985
|
+
throw new NamespaceResolutionError(
|
|
6986
|
+
"agent",
|
|
6987
|
+
name,
|
|
6988
|
+
namespace,
|
|
6989
|
+
`Agent "${shortName}" is not an entry point in package "${pkgId}"`
|
|
6990
|
+
);
|
|
6991
|
+
}
|
|
6992
|
+
const loader = pkg.agents[shortName];
|
|
6993
|
+
if (!loader) {
|
|
6994
|
+
throw new NamespaceResolutionError(
|
|
6995
|
+
"agent",
|
|
6996
|
+
name,
|
|
6997
|
+
namespace,
|
|
6998
|
+
`Agent "${shortName}" not found in package "${pkgId}"`
|
|
6999
|
+
);
|
|
7000
|
+
}
|
|
7001
|
+
return loader;
|
|
7002
|
+
}
|
|
7003
|
+
if (namespace.type === "packed") {
|
|
7004
|
+
const pkg = registry.packages[namespace.packageId];
|
|
7005
|
+
if (!pkg) {
|
|
7006
|
+
throw new NamespaceResolutionError(
|
|
7007
|
+
"agent",
|
|
7008
|
+
name,
|
|
7009
|
+
namespace,
|
|
7010
|
+
`Package "${namespace.packageId}" not found`
|
|
7011
|
+
);
|
|
7012
|
+
}
|
|
7013
|
+
const loader = pkg.agents[shortName];
|
|
7014
|
+
if (!loader) {
|
|
7015
|
+
throw new NamespaceResolutionError(
|
|
7016
|
+
"agent",
|
|
7017
|
+
name,
|
|
7018
|
+
namespace,
|
|
7019
|
+
`Agent "${shortName}" not found in package "${namespace.packageId}"`
|
|
7020
|
+
);
|
|
7021
|
+
}
|
|
7022
|
+
return loader;
|
|
7023
|
+
}
|
|
7024
|
+
const globalLoader = registry.global.agents[shortName];
|
|
7025
|
+
if (globalLoader) {
|
|
7026
|
+
return globalLoader;
|
|
7027
|
+
}
|
|
7028
|
+
for (const [pkgId2, pkg] of Object.entries(registry.packages)) {
|
|
7029
|
+
if (pkg.entryAgents.includes(shortName)) {
|
|
7030
|
+
const loader = pkg.agents[shortName];
|
|
7031
|
+
if (loader) {
|
|
7032
|
+
return loader;
|
|
7033
|
+
}
|
|
7034
|
+
}
|
|
7035
|
+
}
|
|
7036
|
+
throw new NamespaceResolutionError(
|
|
7037
|
+
"agent",
|
|
7038
|
+
name,
|
|
7039
|
+
namespace,
|
|
7040
|
+
`Agent "${shortName}" not found in global namespace`
|
|
7041
|
+
);
|
|
7042
|
+
}
|
|
7043
|
+
function resolveHook(registry, name, namespace) {
|
|
7044
|
+
const [pkgId, shortName] = parseQualifiedName(name);
|
|
7045
|
+
if (pkgId !== null) {
|
|
7046
|
+
throw new NamespaceResolutionError(
|
|
7047
|
+
"hook",
|
|
7048
|
+
name,
|
|
7049
|
+
namespace,
|
|
7050
|
+
`Cannot use qualified hook name "${name}". Hooks must be unqualified.`
|
|
7051
|
+
);
|
|
7052
|
+
}
|
|
7053
|
+
if (namespace.type === "packed") {
|
|
7054
|
+
const pkg = registry.packages[namespace.packageId];
|
|
7055
|
+
if (pkg) {
|
|
7056
|
+
const loader2 = pkg.hooks[shortName];
|
|
7057
|
+
if (loader2) {
|
|
7058
|
+
return loader2;
|
|
7059
|
+
}
|
|
7060
|
+
}
|
|
7061
|
+
return null;
|
|
7062
|
+
}
|
|
7063
|
+
const loader = registry.global.hooks[shortName];
|
|
7064
|
+
return loader || null;
|
|
7065
|
+
}
|
|
7066
|
+
function getVisibleToolNames(registry, namespace) {
|
|
7067
|
+
if (namespace.type === "packed") {
|
|
7068
|
+
const pkg = registry.packages[namespace.packageId];
|
|
7069
|
+
return pkg ? Object.keys(pkg.tools) : [];
|
|
7070
|
+
}
|
|
7071
|
+
return Object.keys(registry.global.tools);
|
|
7072
|
+
}
|
|
7073
|
+
function getVisibleAgentNames(registry, namespace) {
|
|
7074
|
+
if (namespace.type === "packed") {
|
|
7075
|
+
const pkg = registry.packages[namespace.packageId];
|
|
7076
|
+
const ownAgents = pkg ? Object.keys(pkg.agents) : [];
|
|
7077
|
+
const otherEntryPoints = Object.entries(registry.packages).filter(([id]) => id !== namespace.packageId).flatMap(
|
|
7078
|
+
([pkgId, pkg2]) => pkg2.entryAgents.map((name) => qualifyName(pkgId, name))
|
|
7079
|
+
);
|
|
7080
|
+
return [...ownAgents, ...otherEntryPoints];
|
|
7081
|
+
}
|
|
7082
|
+
const globalAgents = Object.keys(registry.global.agents);
|
|
7083
|
+
const entryPoints = Object.values(registry.packages).flatMap((pkg) => pkg.entryAgents);
|
|
7084
|
+
return [.../* @__PURE__ */ new Set([...globalAgents, ...entryPoints])];
|
|
7085
|
+
}
|
|
7086
|
+
function getVisiblePromptNames(registry, namespace) {
|
|
7087
|
+
if (namespace.type === "packed") {
|
|
7088
|
+
const pkg = registry.packages[namespace.packageId];
|
|
7089
|
+
return pkg ? Object.keys(pkg.prompts) : [];
|
|
7090
|
+
}
|
|
7091
|
+
return Object.keys(registry.global.prompts);
|
|
7092
|
+
}
|
|
7093
|
+
function getVisibleModelNames(registry, namespace) {
|
|
7094
|
+
if (namespace.type === "packed") {
|
|
7095
|
+
const pkg = registry.packages[namespace.packageId];
|
|
7096
|
+
const ownModels = pkg ? Object.keys(pkg.models) : [];
|
|
7097
|
+
const globalModels = Object.keys(registry.global.models);
|
|
7098
|
+
return [.../* @__PURE__ */ new Set([...ownModels, ...globalModels])];
|
|
7099
|
+
}
|
|
7100
|
+
return Object.keys(registry.global.models);
|
|
7101
|
+
}
|
|
7102
|
+
function createNamespaceContext(agentDef) {
|
|
7103
|
+
if (agentDef?.__package) {
|
|
7104
|
+
return { type: "packed", packageId: agentDef.__package.packageId };
|
|
7105
|
+
}
|
|
7106
|
+
return { type: "global" };
|
|
7107
|
+
}
|
|
7108
|
+
function isQualifiedName(name) {
|
|
7109
|
+
if (name.startsWith("@")) {
|
|
7110
|
+
const firstSlash = name.indexOf("/");
|
|
7111
|
+
if (firstSlash === -1) return false;
|
|
7112
|
+
return name.indexOf("/", firstSlash + 1) !== -1;
|
|
7113
|
+
}
|
|
7114
|
+
return name.includes("/");
|
|
7115
|
+
}
|
|
7116
|
+
var NamespaceResolutionError;
|
|
7117
|
+
var init_resolver = __esm({
|
|
7118
|
+
"src/packing/resolver.ts"() {
|
|
7119
|
+
NamespaceResolutionError = class extends Error {
|
|
7120
|
+
constructor(itemType, itemName, namespace, message) {
|
|
7121
|
+
super(message);
|
|
7122
|
+
this.itemType = itemType;
|
|
7123
|
+
this.itemName = itemName;
|
|
7124
|
+
this.namespace = namespace;
|
|
7125
|
+
this.name = "NamespaceResolutionError";
|
|
7126
|
+
}
|
|
7127
|
+
};
|
|
7128
|
+
}
|
|
7129
|
+
});
|
|
7130
|
+
|
|
7131
|
+
// src/agents/ParentHookResolver.ts
|
|
7132
|
+
function packageOf(definition) {
|
|
7133
|
+
return definition?.__package ?? definition?._package;
|
|
7134
|
+
}
|
|
7135
|
+
function qualifyWithinPackage(name, packageId) {
|
|
7136
|
+
if (!packageId || parseQualifiedName(name)[0] !== null) {
|
|
7137
|
+
return name;
|
|
7138
|
+
}
|
|
7139
|
+
return qualifyName(packageId, name);
|
|
7140
|
+
}
|
|
7141
|
+
function promptHooks(prompt) {
|
|
7142
|
+
if (!prompt) return [];
|
|
7143
|
+
return Array.isArray(prompt.hooks) ? prompt.hooks : Array.isArray(prompt._hooks) ? prompt._hooks : [];
|
|
7144
|
+
}
|
|
7145
|
+
function promptTools(prompt) {
|
|
7146
|
+
if (!prompt) return [];
|
|
7147
|
+
return Array.isArray(prompt.tools) ? prompt.tools : Array.isArray(prompt._tools) ? prompt._tools : [];
|
|
7148
|
+
}
|
|
7149
|
+
function relationDescriptor(entry) {
|
|
7150
|
+
if (typeof entry === "string") {
|
|
7151
|
+
return {
|
|
7152
|
+
relationshipName: entry,
|
|
7153
|
+
implementingAgent: entry,
|
|
7154
|
+
explicitlyAgentShaped: false
|
|
7155
|
+
};
|
|
7156
|
+
}
|
|
7157
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
7158
|
+
return null;
|
|
7159
|
+
}
|
|
7160
|
+
const config = entry;
|
|
7161
|
+
if (typeof config.name !== "string" || !config.name) {
|
|
7162
|
+
return null;
|
|
7163
|
+
}
|
|
7164
|
+
const implementingAgent = typeof config.agent === "string" && config.agent ? config.agent : config.name;
|
|
7165
|
+
const explicitlyAgentShaped = "agent" in config || "blocking" in config || "resumable" in config || "immediate" in config || "parentCommunication" in config || "hidden" in config;
|
|
7166
|
+
return {
|
|
7167
|
+
relationshipName: config.name,
|
|
7168
|
+
implementingAgent,
|
|
7169
|
+
optional: typeof config.optional === "string" ? config.optional : void 0,
|
|
7170
|
+
explicitlyAgentShaped
|
|
7171
|
+
};
|
|
7172
|
+
}
|
|
7173
|
+
function hookLoader(host, owner, hookId) {
|
|
7174
|
+
const ownerPackage = packageOf(owner);
|
|
7175
|
+
if (!ownerPackage) {
|
|
7176
|
+
return host.hooks()[hookId];
|
|
7177
|
+
}
|
|
7178
|
+
return host.registry?.()?.packages?.[ownerPackage.packageId]?.hooks?.[hookId];
|
|
7179
|
+
}
|
|
7180
|
+
async function loadBinding(host, owner, hookId, hookType, context, required) {
|
|
7181
|
+
const loader = hookLoader(host, owner, hookId);
|
|
7182
|
+
if (!loader) {
|
|
7183
|
+
if (required) {
|
|
7184
|
+
throw new Error(
|
|
7185
|
+
`Required parent hook '${hookId}' was not found in the child agent namespace`
|
|
7186
|
+
);
|
|
7187
|
+
}
|
|
7188
|
+
return null;
|
|
7189
|
+
}
|
|
7190
|
+
let loaded;
|
|
7191
|
+
try {
|
|
7192
|
+
loaded = await loader();
|
|
7193
|
+
} catch (error) {
|
|
7194
|
+
if (required) throw error;
|
|
7195
|
+
console.error(`[Hooks] Failed to load hook '${hookId}':`, error);
|
|
7196
|
+
return null;
|
|
7197
|
+
}
|
|
7198
|
+
if (!loaded) {
|
|
7199
|
+
if (required) {
|
|
7200
|
+
throw new Error(`Required parent hook '${hookId}' did not export a hook definition`);
|
|
7201
|
+
}
|
|
7202
|
+
return null;
|
|
7203
|
+
}
|
|
7204
|
+
if (typeof loaded.id !== "string" || loaded.id !== hookId) {
|
|
7205
|
+
if (required) {
|
|
7206
|
+
throw new Error(`Required parent hook '${hookId}' exported a mismatched hook ID`);
|
|
7207
|
+
}
|
|
7208
|
+
return null;
|
|
7209
|
+
}
|
|
7210
|
+
if (typeof loaded.execute !== "function") {
|
|
7211
|
+
if (required) {
|
|
7212
|
+
throw new Error(`Required parent hook '${hookId}' did not export an execute function`);
|
|
7213
|
+
}
|
|
7214
|
+
return null;
|
|
7215
|
+
}
|
|
7216
|
+
if (USER_HOOK_NAMES.has(loaded.hook)) {
|
|
7217
|
+
if (required) {
|
|
7218
|
+
throw new Error(
|
|
7219
|
+
`Required parent hook '${hookId}' uses user-scoped hook type '${loaded.hook}'`
|
|
7220
|
+
);
|
|
7221
|
+
}
|
|
7222
|
+
return null;
|
|
7223
|
+
}
|
|
7224
|
+
if (!THREAD_HOOK_NAMES.has(loaded.hook)) {
|
|
7225
|
+
if (required) {
|
|
7226
|
+
throw new Error(`Required parent hook '${hookId}' exported invalid hook type '${loaded.hook}'`);
|
|
7227
|
+
}
|
|
7228
|
+
return null;
|
|
7229
|
+
}
|
|
7230
|
+
if (loaded.hook !== hookType) {
|
|
7231
|
+
return null;
|
|
7232
|
+
}
|
|
7233
|
+
return {
|
|
7234
|
+
id: hookId,
|
|
7235
|
+
hook: hookType,
|
|
7236
|
+
execute: loaded.execute,
|
|
7237
|
+
context
|
|
7238
|
+
};
|
|
7239
|
+
}
|
|
7240
|
+
async function resolveHooksForPrompt(input, hookType) {
|
|
7241
|
+
const agent = input.agent ?? await input.host.loadAgent(input.agentName);
|
|
7242
|
+
const agentPackage = packageOf(agent);
|
|
7243
|
+
const unqualifiedPromptName = input.promptName ?? agent.sideA?.prompt;
|
|
7244
|
+
const resolvedPromptName = unqualifiedPromptName ? qualifyWithinPackage(unqualifiedPromptName, agentPackage?.packageId) : void 0;
|
|
7245
|
+
const prompt = input.prompt ?? (resolvedPromptName ? await input.host.loadPrompt(resolvedPromptName) : void 0);
|
|
7246
|
+
const promptName = prompt?.name ?? prompt?.id ?? resolvedPromptName ?? "unknown_prompt";
|
|
7247
|
+
const before = [];
|
|
7248
|
+
const after = [];
|
|
7249
|
+
for (const entry of promptTools(prompt)) {
|
|
7250
|
+
const relation = relationDescriptor(entry);
|
|
7251
|
+
if (!relation) continue;
|
|
7252
|
+
if (relation.optional && input.isOptionalRelationshipEnabled && !await input.isOptionalRelationshipEnabled(relation.optional)) {
|
|
7253
|
+
continue;
|
|
7254
|
+
}
|
|
7255
|
+
const promptPackage = packageOf(prompt) ?? agentPackage;
|
|
7256
|
+
const childReference = qualifyWithinPackage(
|
|
7257
|
+
relation.implementingAgent,
|
|
7258
|
+
promptPackage?.packageId
|
|
7259
|
+
);
|
|
7260
|
+
let child;
|
|
7261
|
+
try {
|
|
7262
|
+
child = await input.host.loadAgent(childReference);
|
|
7263
|
+
} catch (error) {
|
|
7264
|
+
if (relation.explicitlyAgentShaped) throw error;
|
|
7265
|
+
continue;
|
|
7266
|
+
}
|
|
7267
|
+
if (child.type !== "dual_ai") continue;
|
|
7268
|
+
if (child.parentHooks !== void 0 && child.exposeAsTool !== true) {
|
|
7269
|
+
throw new Error(
|
|
7270
|
+
`Child agent '${childReference}' declares parentHooks but is not exposed as a tool`
|
|
7271
|
+
);
|
|
7272
|
+
}
|
|
7273
|
+
if (child.parentHooks !== void 0 && !Array.isArray(child.parentHooks)) {
|
|
7274
|
+
throw new Error(`Child agent '${childReference}' has an invalid parentHooks declaration`);
|
|
7275
|
+
}
|
|
7276
|
+
const requirements = child.parentHooks ?? [];
|
|
7277
|
+
const seenRequirements = /* @__PURE__ */ new Set();
|
|
7278
|
+
for (const requirement of requirements) {
|
|
7279
|
+
if (!requirement || typeof requirement !== "object" || typeof requirement.hook !== "string" || !requirement.hook || typeof requirement.reason !== "string" || !requirement.reason.trim() || requirement.stage !== void 0 && requirement.stage !== "before_parent" && requirement.stage !== "after_parent" || seenRequirements.has(requirement.hook)) {
|
|
7280
|
+
throw new Error(`Child agent '${childReference}' has an invalid parentHooks requirement`);
|
|
7281
|
+
}
|
|
7282
|
+
seenRequirements.add(requirement.hook);
|
|
7283
|
+
const loaded = await loadBinding(
|
|
7284
|
+
input.host,
|
|
7285
|
+
child,
|
|
7286
|
+
requirement.hook,
|
|
7287
|
+
hookType,
|
|
7288
|
+
{
|
|
7289
|
+
source: {
|
|
7290
|
+
kind: "child",
|
|
7291
|
+
relationshipName: relation.relationshipName,
|
|
7292
|
+
agentName: childReference,
|
|
7293
|
+
package: packageOf(child)
|
|
7294
|
+
}
|
|
7295
|
+
},
|
|
7296
|
+
true
|
|
7297
|
+
);
|
|
7298
|
+
if (!loaded) continue;
|
|
7299
|
+
if ((requirement.stage ?? "after_parent") === "before_parent") {
|
|
7300
|
+
before.push(loaded);
|
|
7301
|
+
} else {
|
|
7302
|
+
after.push(loaded);
|
|
7303
|
+
}
|
|
7304
|
+
}
|
|
7305
|
+
}
|
|
7306
|
+
const promptHookIds = promptHooks(prompt);
|
|
7307
|
+
const promptOwnsBaseHooks = promptHookIds.length > 0 && prompt !== void 0;
|
|
7308
|
+
const baseOwner = promptOwnsBaseHooks ? prompt : agent;
|
|
7309
|
+
const baseIds = promptHookIds.length > 0 ? promptHookIds : Array.isArray(agent.hooks) ? agent.hooks : [];
|
|
7310
|
+
const baseContext = promptOwnsBaseHooks ? { source: { kind: "prompt", promptName } } : { source: { kind: "agent", agentName: input.agentName } };
|
|
7311
|
+
const base = [];
|
|
7312
|
+
for (const hookId of baseIds) {
|
|
7313
|
+
const loaded = await loadBinding(
|
|
7314
|
+
input.host,
|
|
7315
|
+
baseOwner,
|
|
7316
|
+
hookId,
|
|
7317
|
+
hookType,
|
|
7318
|
+
baseContext,
|
|
7319
|
+
false
|
|
7320
|
+
);
|
|
7321
|
+
if (loaded) base.push(loaded);
|
|
7322
|
+
}
|
|
7323
|
+
return [...before, ...base, ...after];
|
|
7324
|
+
}
|
|
7325
|
+
var USER_HOOK_NAMES, THREAD_HOOK_NAMES;
|
|
7326
|
+
var init_ParentHookResolver = __esm({
|
|
7327
|
+
"src/agents/ParentHookResolver.ts"() {
|
|
7328
|
+
init_resolver();
|
|
7329
|
+
USER_HOOK_NAMES = /* @__PURE__ */ new Set([
|
|
7330
|
+
"user_client_attached",
|
|
7331
|
+
"user_client_detached",
|
|
7332
|
+
"user_value_changed"
|
|
7333
|
+
]);
|
|
7334
|
+
THREAD_HOOK_NAMES = /* @__PURE__ */ new Set([
|
|
7335
|
+
"after_thread_created",
|
|
7336
|
+
"after_subagent_created",
|
|
7337
|
+
"after_system_message",
|
|
7338
|
+
"filter_messages",
|
|
7339
|
+
"prefilter_llm_history",
|
|
7340
|
+
"before_create_message",
|
|
7341
|
+
"after_create_message",
|
|
7342
|
+
"before_update_message",
|
|
7343
|
+
"after_update_message",
|
|
7344
|
+
"before_store_tool_result",
|
|
7345
|
+
"after_tool_call_success",
|
|
7346
|
+
"after_tool_call_failure",
|
|
7347
|
+
"tool_call_started",
|
|
7348
|
+
"tool_call_done"
|
|
7349
|
+
]);
|
|
7350
|
+
}
|
|
7351
|
+
});
|
|
7352
|
+
|
|
6812
7353
|
// src/agents/FlowEngine.ts
|
|
6813
7354
|
var FlowEngine_exports = {};
|
|
6814
7355
|
__export(FlowEngine_exports, {
|
|
@@ -6825,6 +7366,7 @@ var init_FlowEngine = __esm({
|
|
|
6825
7366
|
init_context();
|
|
6826
7367
|
init_sessionTools();
|
|
6827
7368
|
init_ThreadStateImpl();
|
|
7369
|
+
init_ParentHookResolver();
|
|
6828
7370
|
IMMEDIATE_BOOTSTRAP_TOOL_NAME = "bootstrap_immediate_subagent";
|
|
6829
7371
|
HookBlockedExecutionError = class extends Error {
|
|
6830
7372
|
constructor(message) {
|
|
@@ -7167,7 +7709,8 @@ This usually points to something I can't fix from here \u2014 for example the wo
|
|
|
7167
7709
|
_variables: def.variables ?? [],
|
|
7168
7710
|
_env: def.env ?? def.tenvs ?? {},
|
|
7169
7711
|
_requiredSchema: def.requiredSchema ?? null,
|
|
7170
|
-
_hooks: def.hooks ?? []
|
|
7712
|
+
_hooks: def.hooks ?? [],
|
|
7713
|
+
_package: def.__package
|
|
7171
7714
|
};
|
|
7172
7715
|
}
|
|
7173
7716
|
/**
|
|
@@ -7557,6 +8100,8 @@ This usually points to something I can't fix from here \u2014 for example the wo
|
|
|
7557
8100
|
type: newAgentDef.type,
|
|
7558
8101
|
created_at: Date.now(),
|
|
7559
8102
|
max_session_turns: newAgentDef.maxSessionTurns ?? null,
|
|
8103
|
+
hooks: newAgentDef.hooks ?? [],
|
|
8104
|
+
_package: newAgentDef.__package,
|
|
7560
8105
|
side_a_label: newAgentDef.sideA?.label ?? null,
|
|
7561
8106
|
side_a_agent_prompt: newAgentDef.sideA?.prompt ?? null,
|
|
7562
8107
|
side_a_stop_on_response: newAgentDef.sideA?.stopOnResponse ?? true,
|
|
@@ -7717,7 +8262,7 @@ This usually points to something I can't fix from here \u2014 for example the wo
|
|
|
7717
8262
|
return null;
|
|
7718
8263
|
}
|
|
7719
8264
|
return await stub.resolveThreadEnv({
|
|
7720
|
-
threadId: state.
|
|
8265
|
+
threadId: state.thread.metadata.id,
|
|
7721
8266
|
property,
|
|
7722
8267
|
promptName: state.prompt?.name
|
|
7723
8268
|
});
|
|
@@ -8239,8 +8784,8 @@ This usually points to something I can't fix from here \u2014 for example the wo
|
|
|
8239
8784
|
state.context[key] = existing;
|
|
8240
8785
|
}
|
|
8241
8786
|
static async runImmediateToolsIfNeeded(state) {
|
|
8242
|
-
const
|
|
8243
|
-
if (
|
|
8787
|
+
const promptTools2 = Array.isArray(state.prompt._tools) ? state.prompt._tools : [];
|
|
8788
|
+
if (promptTools2.length === 0) {
|
|
8244
8789
|
return false;
|
|
8245
8790
|
}
|
|
8246
8791
|
if (!state.immediatePromptRuns) {
|
|
@@ -8276,7 +8821,7 @@ This usually points to something I can't fix from here \u2014 for example the wo
|
|
|
8276
8821
|
(activeInstanceCounts.get(child.name) ?? 0) + 1
|
|
8277
8822
|
);
|
|
8278
8823
|
}
|
|
8279
|
-
for (const toolConfig of
|
|
8824
|
+
for (const toolConfig of promptTools2) {
|
|
8280
8825
|
if (!toolConfig || typeof toolConfig !== "object") {
|
|
8281
8826
|
continue;
|
|
8282
8827
|
}
|
|
@@ -8442,10 +8987,10 @@ This usually points to something I can't fix from here \u2014 for example the wo
|
|
|
8442
8987
|
* model's to clean up, and terminate_subagent on an infrastructure child
|
|
8443
8988
|
* kills work the runtime depends on. Static and pure for direct testing.
|
|
8444
8989
|
*/
|
|
8445
|
-
static filterModelVisibleSubagents(registry,
|
|
8990
|
+
static filterModelVisibleSubagents(registry, promptTools2) {
|
|
8446
8991
|
if (registry.length === 0) return registry;
|
|
8447
8992
|
const hidden = /* @__PURE__ */ new Set();
|
|
8448
|
-
for (const config of
|
|
8993
|
+
for (const config of promptTools2 ?? []) {
|
|
8449
8994
|
if (typeof config === "object" && config !== null && "name" in config && config.hidden === true) {
|
|
8450
8995
|
hidden.add(config.name);
|
|
8451
8996
|
}
|
|
@@ -9475,8 +10020,8 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
9475
10020
|
try {
|
|
9476
10021
|
const nativeTools = await this.loadNativeTools(state);
|
|
9477
10022
|
tools.push(...nativeTools);
|
|
9478
|
-
const
|
|
9479
|
-
tools.push(...
|
|
10023
|
+
const promptTools2 = await this.loadPromptTools(state);
|
|
10024
|
+
tools.push(...promptTools2);
|
|
9480
10025
|
const agentTools = await this.loadAgentTools(state);
|
|
9481
10026
|
tools.push(...agentTools);
|
|
9482
10027
|
const toolNameSources = /* @__PURE__ */ new Map();
|
|
@@ -9485,7 +10030,7 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
9485
10030
|
sources.add("native tool");
|
|
9486
10031
|
toolNameSources.set(tool.function.name, sources);
|
|
9487
10032
|
}
|
|
9488
|
-
for (const tool of
|
|
10033
|
+
for (const tool of promptTools2) {
|
|
9489
10034
|
const sources = toolNameSources.get(tool.function.name) || /* @__PURE__ */ new Set();
|
|
9490
10035
|
sources.add("prompt");
|
|
9491
10036
|
toolNameSources.set(tool.function.name, sources);
|
|
@@ -9627,24 +10172,8 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
9627
10172
|
// Hook Resolution Helpers
|
|
9628
10173
|
// ==========================================================================
|
|
9629
10174
|
/**
|
|
9630
|
-
*
|
|
9631
|
-
*
|
|
9632
|
-
*
|
|
9633
|
-
* @param state - Flow state with prompt and agent configuration
|
|
9634
|
-
* @returns Array of hook IDs to execute
|
|
9635
|
-
*/
|
|
9636
|
-
static getActiveHookIds(state) {
|
|
9637
|
-
if (state.prompt?._hooks !== void 0 && state.prompt._hooks.length > 0) {
|
|
9638
|
-
return state.prompt._hooks;
|
|
9639
|
-
}
|
|
9640
|
-
if (state.agentConfig.hooks !== void 0 && state.agentConfig.hooks.length > 0) {
|
|
9641
|
-
return state.agentConfig.hooks;
|
|
9642
|
-
}
|
|
9643
|
-
return [];
|
|
9644
|
-
}
|
|
9645
|
-
/**
|
|
9646
|
-
* Get hooks of a specific type from the active hook IDs.
|
|
9647
|
-
* Returns typed hook executors in the order they appear in the hooks array.
|
|
10175
|
+
* Resolve hooks of a specific type for the active prompt, including required
|
|
10176
|
+
* hooks contributed automatically by its enabled direct child agents.
|
|
9648
10177
|
*
|
|
9649
10178
|
* @template K - The hook type name (ensures type-safe executors)
|
|
9650
10179
|
* @param state - Flow state with hook configuration
|
|
@@ -9652,24 +10181,17 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
9652
10181
|
* @returns Array of typed hook executor functions
|
|
9653
10182
|
*/
|
|
9654
10183
|
static async getHooksForType(state, hookType) {
|
|
9655
|
-
|
|
9656
|
-
|
|
9657
|
-
|
|
9658
|
-
|
|
9659
|
-
|
|
9660
|
-
|
|
9661
|
-
|
|
9662
|
-
|
|
9663
|
-
|
|
9664
|
-
|
|
9665
|
-
|
|
9666
|
-
executors.push(hookDef.execute);
|
|
9667
|
-
}
|
|
9668
|
-
} catch (error) {
|
|
9669
|
-
console.error(`[Hooks] Failed to load hook '${hookId}':`, error);
|
|
9670
|
-
}
|
|
9671
|
-
}
|
|
9672
|
-
return executors;
|
|
10184
|
+
return await resolveHooksForPrompt(
|
|
10185
|
+
{
|
|
10186
|
+
host: state.thread.instance,
|
|
10187
|
+
agentName: state.agentConfig.id,
|
|
10188
|
+
agent: state.agentConfig,
|
|
10189
|
+
promptName: state.prompt?.id,
|
|
10190
|
+
prompt: state.prompt,
|
|
10191
|
+
isOptionalRelationshipEnabled: (envName) => this.isOptionalToolEnabled(state, envName)
|
|
10192
|
+
},
|
|
10193
|
+
hookType
|
|
10194
|
+
);
|
|
9673
10195
|
}
|
|
9674
10196
|
// ==========================================================================
|
|
9675
10197
|
// Hook Runner Methods
|
|
@@ -9687,9 +10209,9 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
9687
10209
|
if (executors.length === 0) return messages;
|
|
9688
10210
|
let result = messages;
|
|
9689
10211
|
const threadState = ThreadStateImpl.fromFlowState(state);
|
|
9690
|
-
for (const
|
|
10212
|
+
for (const { execute, context } of executors) {
|
|
9691
10213
|
try {
|
|
9692
|
-
result = await
|
|
10214
|
+
result = await execute(threadState, result, context);
|
|
9693
10215
|
} catch (error) {
|
|
9694
10216
|
if (error && typeof error === "object" && error.block === true) {
|
|
9695
10217
|
throw new HookBlockedExecutionError(error instanceof Error ? error.message : String(error));
|
|
@@ -9707,9 +10229,9 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
9707
10229
|
if (executors.length === 0) return systemMessage;
|
|
9708
10230
|
let result = systemMessage;
|
|
9709
10231
|
const threadState = ThreadStateImpl.fromFlowState(state);
|
|
9710
|
-
for (const
|
|
10232
|
+
for (const { execute, context } of executors) {
|
|
9711
10233
|
try {
|
|
9712
|
-
const next = await
|
|
10234
|
+
const next = await execute(threadState, result, context);
|
|
9713
10235
|
if (next !== null && next !== void 0) {
|
|
9714
10236
|
result = next;
|
|
9715
10237
|
}
|
|
@@ -9726,9 +10248,9 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
9726
10248
|
const executors = await this.getHooksForType(state, "after_subagent_created");
|
|
9727
10249
|
if (executors.length === 0) return;
|
|
9728
10250
|
const threadState = ThreadStateImpl.fromFlowState(state);
|
|
9729
|
-
for (const
|
|
10251
|
+
for (const { execute, context } of executors) {
|
|
9730
10252
|
try {
|
|
9731
|
-
await
|
|
10253
|
+
await execute(threadState, childState, context);
|
|
9732
10254
|
} catch (error) {
|
|
9733
10255
|
console.error("[Hooks] \u2717 Error running after_subagent_created hook:", error);
|
|
9734
10256
|
}
|
|
@@ -9747,9 +10269,13 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
9747
10269
|
if (executors.length === 0) return message;
|
|
9748
10270
|
let result = message;
|
|
9749
10271
|
const threadState = threadStateOverride ?? ThreadStateImpl.fromFlowState(state);
|
|
9750
|
-
for (const
|
|
10272
|
+
for (const { execute, context } of executors) {
|
|
9751
10273
|
try {
|
|
9752
|
-
const hooked = await
|
|
10274
|
+
const hooked = await execute(
|
|
10275
|
+
threadState,
|
|
10276
|
+
_FlowEngine.rowToHookMessage(result),
|
|
10277
|
+
context
|
|
10278
|
+
);
|
|
9753
10279
|
result = {
|
|
9754
10280
|
...result,
|
|
9755
10281
|
...hooked,
|
|
@@ -9775,9 +10301,9 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
9775
10301
|
const executors = await this.getHooksForType(state, "after_create_message");
|
|
9776
10302
|
if (executors.length === 0) return;
|
|
9777
10303
|
const threadState = threadStateOverride ?? ThreadStateImpl.fromFlowState(state);
|
|
9778
|
-
for (const
|
|
10304
|
+
for (const { execute, context } of executors) {
|
|
9779
10305
|
try {
|
|
9780
|
-
await
|
|
10306
|
+
await execute(threadState, _FlowEngine.rowToHookMessage(message), context);
|
|
9781
10307
|
} catch (error) {
|
|
9782
10308
|
console.error("[Hooks] \u2717 Error running after_create_message hook:", error);
|
|
9783
10309
|
}
|
|
@@ -9818,9 +10344,9 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
9818
10344
|
if (executors.length === 0) return updates;
|
|
9819
10345
|
let result = updates;
|
|
9820
10346
|
const threadState = ThreadStateImpl.fromFlowState(state);
|
|
9821
|
-
for (const
|
|
10347
|
+
for (const { execute, context } of executors) {
|
|
9822
10348
|
try {
|
|
9823
|
-
result = await
|
|
10349
|
+
result = await execute(threadState, messageId, result, context);
|
|
9824
10350
|
} catch (error) {
|
|
9825
10351
|
console.error("[Hooks] \u2717 Error running before_update_message hook:", error);
|
|
9826
10352
|
}
|
|
@@ -9838,9 +10364,9 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
9838
10364
|
const executors = await this.getHooksForType(state, "after_update_message");
|
|
9839
10365
|
if (executors.length === 0) return;
|
|
9840
10366
|
const threadState = ThreadStateImpl.fromFlowState(state);
|
|
9841
|
-
for (const
|
|
10367
|
+
for (const { execute, context } of executors) {
|
|
9842
10368
|
try {
|
|
9843
|
-
await
|
|
10369
|
+
await execute(threadState, _FlowEngine.rowToHookMessage(message), context);
|
|
9844
10370
|
} catch (error) {
|
|
9845
10371
|
console.error("[Hooks] \u2717 Error running after_update_message hook:", error);
|
|
9846
10372
|
}
|
|
@@ -9860,9 +10386,9 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
9860
10386
|
if (executors.length === 0) return toolResult;
|
|
9861
10387
|
let result = toolResult;
|
|
9862
10388
|
const threadState = ThreadStateImpl.fromFlowState(state);
|
|
9863
|
-
for (const
|
|
10389
|
+
for (const { execute, context } of executors) {
|
|
9864
10390
|
try {
|
|
9865
|
-
result = await
|
|
10391
|
+
result = await execute(threadState, toolCall, result, context);
|
|
9866
10392
|
} catch (error) {
|
|
9867
10393
|
console.error("[Hooks] \u2717 Error running before_store_tool_result hook:", error);
|
|
9868
10394
|
}
|
|
@@ -9882,10 +10408,10 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
9882
10408
|
if (executors.length === 0) return toolResult;
|
|
9883
10409
|
let result = toolResult;
|
|
9884
10410
|
const threadState = ThreadStateImpl.fromFlowState(state);
|
|
9885
|
-
for (const
|
|
10411
|
+
for (const { execute, context } of executors) {
|
|
9886
10412
|
if (result === null) break;
|
|
9887
10413
|
try {
|
|
9888
|
-
result = await
|
|
10414
|
+
result = await execute(threadState, toolCall, result, context);
|
|
9889
10415
|
} catch (error) {
|
|
9890
10416
|
console.error("[Hooks] \u2717 Error running after_tool_call_success hook:", error);
|
|
9891
10417
|
}
|
|
@@ -9905,10 +10431,10 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
9905
10431
|
if (executors.length === 0) return toolResult;
|
|
9906
10432
|
let result = toolResult;
|
|
9907
10433
|
const threadState = ThreadStateImpl.fromFlowState(state);
|
|
9908
|
-
for (const
|
|
10434
|
+
for (const { execute, context } of executors) {
|
|
9909
10435
|
if (result === null) break;
|
|
9910
10436
|
try {
|
|
9911
|
-
result = await
|
|
10437
|
+
result = await execute(threadState, toolCall, result, context);
|
|
9912
10438
|
} catch (error) {
|
|
9913
10439
|
console.error("[Hooks] \u2717 Error running after_tool_call_failure hook:", error);
|
|
9914
10440
|
}
|
|
@@ -9938,9 +10464,9 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
9938
10464
|
const executors = await this.getHooksForType(state, "tool_call_started");
|
|
9939
10465
|
if (executors.length === 0) return;
|
|
9940
10466
|
const threadState = ThreadStateImpl.fromFlowState(state);
|
|
9941
|
-
for (const
|
|
10467
|
+
for (const { execute, context } of executors) {
|
|
9942
10468
|
try {
|
|
9943
|
-
await
|
|
10469
|
+
await execute(threadState, toolCall, progress, context);
|
|
9944
10470
|
} catch (error) {
|
|
9945
10471
|
console.error("[Hooks] \u2717 Error running tool_call_started hook:", error);
|
|
9946
10472
|
}
|
|
@@ -9968,9 +10494,9 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
9968
10494
|
const executors = await this.getHooksForType(state, "tool_call_done");
|
|
9969
10495
|
if (executors.length === 0) return;
|
|
9970
10496
|
const threadState = ThreadStateImpl.fromFlowState(state);
|
|
9971
|
-
for (const
|
|
10497
|
+
for (const { execute, context } of executors) {
|
|
9972
10498
|
try {
|
|
9973
|
-
await
|
|
10499
|
+
await execute(threadState, toolCall, toolResult, context);
|
|
9974
10500
|
} catch (error) {
|
|
9975
10501
|
console.error("[Hooks] \u2717 Error running tool_call_done hook:", error);
|
|
9976
10502
|
}
|
|
@@ -10923,12 +11449,12 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
10923
11449
|
if (executors.length === 0) return messages;
|
|
10924
11450
|
let result = messages;
|
|
10925
11451
|
const threadState = ThreadStateImpl.fromFlowState(state);
|
|
10926
|
-
for (const
|
|
11452
|
+
for (const { execute, context } of executors) {
|
|
10927
11453
|
try {
|
|
10928
11454
|
const byId = /* @__PURE__ */ new Map();
|
|
10929
11455
|
for (const row of result) if (row.id) byId.set(row.id, row);
|
|
10930
11456
|
const hookView = result.map((row) => _FlowEngine.rowToHookMessage(row));
|
|
10931
|
-
const kept = await
|
|
11457
|
+
const kept = await execute(threadState, hookView, context);
|
|
10932
11458
|
result = kept.map((hookedMessage) => {
|
|
10933
11459
|
const original = hookedMessage.id ? byId.get(hookedMessage.id) : void 0;
|
|
10934
11460
|
if (original) {
|
|
@@ -17013,6 +17539,10 @@ function generateAgentFile(data) {
|
|
|
17013
17539
|
if (data.toolDescription) {
|
|
17014
17540
|
lines.push(` toolDescription: '${escapeString3(data.toolDescription)}',`);
|
|
17015
17541
|
}
|
|
17542
|
+
if (data.parentHooks && data.parentHooks.length > 0) {
|
|
17543
|
+
const serialized = JSON.stringify(data.parentHooks, null, 2).split("\n").map((line, index) => index === 0 ? line : ` ${line}`).join("\n");
|
|
17544
|
+
lines.push(` parentHooks: ${serialized},`);
|
|
17545
|
+
}
|
|
17016
17546
|
const env = data.env ?? (data.tenvs || void 0);
|
|
17017
17547
|
if (env && Object.keys(env).length > 0) {
|
|
17018
17548
|
lines.push(` env: ${JSON.stringify(env)},`);
|
|
@@ -17782,6 +18312,9 @@ function transformAgentData(data) {
|
|
|
17782
18312
|
if (data.tool_description) {
|
|
17783
18313
|
transformed.toolDescription = data.tool_description;
|
|
17784
18314
|
}
|
|
18315
|
+
if (data.parent_hooks !== void 0 || data.parentHooks !== void 0) {
|
|
18316
|
+
transformed.parentHooks = data.parent_hooks ?? data.parentHooks;
|
|
18317
|
+
}
|
|
17785
18318
|
if (data.env !== void 0 || data.tenvs !== void 0) {
|
|
17786
18319
|
transformed.env = normalizeStringEnvRecord(data.env ?? data.tenvs) ?? {};
|
|
17787
18320
|
}
|
|
@@ -18027,6 +18560,22 @@ function validateAgentData(data) {
|
|
|
18027
18560
|
if (data.exposeAsTool && !data.toolDescription) {
|
|
18028
18561
|
errors["tool_description"] = "Tool description is required when expose as tool is enabled";
|
|
18029
18562
|
}
|
|
18563
|
+
if (data.parentHooks !== void 0) {
|
|
18564
|
+
if (!Array.isArray(data.parentHooks)) {
|
|
18565
|
+
errors["parent_hooks"] = "Parent hooks must be an array";
|
|
18566
|
+
} else if (data.type !== "dual_ai" || !data.exposeAsTool) {
|
|
18567
|
+
errors["parent_hooks"] = "Parent hooks require an exposed dual_ai agent";
|
|
18568
|
+
} else {
|
|
18569
|
+
const seen = /* @__PURE__ */ new Set();
|
|
18570
|
+
for (const requirement of data.parentHooks) {
|
|
18571
|
+
if (!requirement || typeof requirement !== "object" || typeof requirement.hook !== "string" || !requirement.hook || typeof requirement.reason !== "string" || !requirement.reason.trim() || requirement.stage !== void 0 && requirement.stage !== "before_parent" && requirement.stage !== "after_parent" || seen.has(requirement.hook)) {
|
|
18572
|
+
errors["parent_hooks"] = "Parent hook entries require a unique hook, reason, and valid stage";
|
|
18573
|
+
break;
|
|
18574
|
+
}
|
|
18575
|
+
seen.add(requirement.hook);
|
|
18576
|
+
}
|
|
18577
|
+
}
|
|
18578
|
+
}
|
|
18030
18579
|
if (data.maxSessionTurns !== void 0 && data.maxSessionTurns !== null) {
|
|
18031
18580
|
if (typeof data.maxSessionTurns !== "number" || data.maxSessionTurns <= 0) {
|
|
18032
18581
|
errors["max_session_turns"] = "Max session turns must be a positive number";
|
|
@@ -18172,6 +18721,44 @@ function discoverPackedPackageDirectories(packedDir) {
|
|
|
18172
18721
|
}
|
|
18173
18722
|
return packageDirs;
|
|
18174
18723
|
}
|
|
18724
|
+
function discoverStandardAgentPackageDirectories(rootDir) {
|
|
18725
|
+
const packages = /* @__PURE__ */ new Map();
|
|
18726
|
+
const addPackage = (packagePath, source) => {
|
|
18727
|
+
const packageJsonPath = path9__default.join(packagePath, "package.json");
|
|
18728
|
+
if (!fs9__default.existsSync(packageJsonPath)) return;
|
|
18729
|
+
try {
|
|
18730
|
+
const packageJson = JSON.parse(fs9__default.readFileSync(packageJsonPath, "utf8"));
|
|
18731
|
+
if (typeof packageJson.name !== "string" || !Array.isArray(packageJson.standardagent?.entryAgents)) {
|
|
18732
|
+
return;
|
|
18733
|
+
}
|
|
18734
|
+
packages.set(packageJson.name, { path: packagePath, source });
|
|
18735
|
+
} catch {
|
|
18736
|
+
}
|
|
18737
|
+
};
|
|
18738
|
+
const nodeModulesDir = path9__default.join(rootDir, "node_modules");
|
|
18739
|
+
if (fs9__default.existsSync(nodeModulesDir)) {
|
|
18740
|
+
for (const entry of fs9__default.readdirSync(nodeModulesDir, { withFileTypes: true })) {
|
|
18741
|
+
if (entry.name.startsWith(".")) continue;
|
|
18742
|
+
const entryPath = path9__default.join(nodeModulesDir, entry.name);
|
|
18743
|
+
if (entry.name.startsWith("@")) {
|
|
18744
|
+
if (!fs9__default.existsSync(entryPath)) continue;
|
|
18745
|
+
for (const scopedEntry of fs9__default.readdirSync(entryPath, { withFileTypes: true })) {
|
|
18746
|
+
if (!scopedEntry.name.startsWith(".")) {
|
|
18747
|
+
addPackage(path9__default.join(entryPath, scopedEntry.name), "npm");
|
|
18748
|
+
}
|
|
18749
|
+
}
|
|
18750
|
+
} else {
|
|
18751
|
+
addPackage(entryPath, "npm");
|
|
18752
|
+
}
|
|
18753
|
+
}
|
|
18754
|
+
}
|
|
18755
|
+
for (const packagePath of discoverPackedPackageDirectories(
|
|
18756
|
+
path9__default.join(rootDir, "agents", "packed")
|
|
18757
|
+
)) {
|
|
18758
|
+
addPackage(packagePath, "local");
|
|
18759
|
+
}
|
|
18760
|
+
return [...packages.values()];
|
|
18761
|
+
}
|
|
18175
18762
|
function scanPackedDistDirectory(packagePath, outputDir, subDir) {
|
|
18176
18763
|
const fullPath = path9__default.join(packagePath, outputDir, subDir);
|
|
18177
18764
|
if (!fs9__default.existsSync(fullPath)) {
|
|
@@ -19115,11 +19702,19 @@ async function extractPromptTools(sourceCode) {
|
|
|
19115
19702
|
result.tools.push(element.text);
|
|
19116
19703
|
} else if (ts.isObjectLiteralExpression(element)) {
|
|
19117
19704
|
result.hasSubpromptConfigs = true;
|
|
19705
|
+
let configuredName;
|
|
19706
|
+
let implementingAgent;
|
|
19118
19707
|
for (const objProp of element.properties) {
|
|
19119
|
-
if (ts.isPropertyAssignment(objProp) && ts.isIdentifier(objProp.name) &&
|
|
19120
|
-
|
|
19708
|
+
if (ts.isPropertyAssignment(objProp) && ts.isIdentifier(objProp.name) && ts.isStringLiteral(objProp.initializer)) {
|
|
19709
|
+
if (objProp.name.text === "name") {
|
|
19710
|
+
configuredName = objProp.initializer.text;
|
|
19711
|
+
} else if (objProp.name.text === "agent") {
|
|
19712
|
+
implementingAgent = objProp.initializer.text;
|
|
19713
|
+
}
|
|
19121
19714
|
}
|
|
19122
19715
|
}
|
|
19716
|
+
const dependencyName = implementingAgent ?? configuredName;
|
|
19717
|
+
if (dependencyName) result.tools.push(dependencyName);
|
|
19123
19718
|
}
|
|
19124
19719
|
}
|
|
19125
19720
|
}
|
|
@@ -19242,6 +19837,106 @@ async function extractAgentPrompts(sourceCode) {
|
|
|
19242
19837
|
visit(sourceFile);
|
|
19243
19838
|
return result;
|
|
19244
19839
|
}
|
|
19840
|
+
async function extractAgentHooks(sourceCode) {
|
|
19841
|
+
const ts = await loadTypeScript();
|
|
19842
|
+
const sourceFile = ts.createSourceFile(
|
|
19843
|
+
"agent.ts",
|
|
19844
|
+
sourceCode,
|
|
19845
|
+
ts.ScriptTarget.ESNext,
|
|
19846
|
+
true
|
|
19847
|
+
);
|
|
19848
|
+
const arrays = /* @__PURE__ */ new Map();
|
|
19849
|
+
const result = {
|
|
19850
|
+
hooks: [],
|
|
19851
|
+
parentHooks: [],
|
|
19852
|
+
parentHookRequirements: []
|
|
19853
|
+
};
|
|
19854
|
+
const unwrapArray = (expression) => {
|
|
19855
|
+
let current = expression;
|
|
19856
|
+
while (ts.isParenthesizedExpression(current) || ts.isAsExpression(current) || ts.isSatisfiesExpression(current)) {
|
|
19857
|
+
current = current.expression;
|
|
19858
|
+
}
|
|
19859
|
+
if (ts.isArrayLiteralExpression(current)) return current;
|
|
19860
|
+
if (ts.isIdentifier(current)) return arrays.get(current.text) ?? null;
|
|
19861
|
+
return null;
|
|
19862
|
+
};
|
|
19863
|
+
for (const statement of sourceFile.statements) {
|
|
19864
|
+
if (!ts.isVariableStatement(statement)) continue;
|
|
19865
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
19866
|
+
if (ts.isIdentifier(declaration.name) && declaration.initializer) {
|
|
19867
|
+
const array = unwrapArray(declaration.initializer);
|
|
19868
|
+
if (array) arrays.set(declaration.name.text, array);
|
|
19869
|
+
}
|
|
19870
|
+
}
|
|
19871
|
+
}
|
|
19872
|
+
const pushUnique = (target, value) => {
|
|
19873
|
+
if (!target.includes(value)) target.push(value);
|
|
19874
|
+
};
|
|
19875
|
+
function visit(node) {
|
|
19876
|
+
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "defineAgent" && node.arguments.length > 0 && ts.isObjectLiteralExpression(node.arguments[0])) {
|
|
19877
|
+
for (const property of node.arguments[0].properties) {
|
|
19878
|
+
if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name)) continue;
|
|
19879
|
+
const array = unwrapArray(property.initializer);
|
|
19880
|
+
if (!array) continue;
|
|
19881
|
+
if (property.name.text === "hooks") {
|
|
19882
|
+
for (const element of array.elements) {
|
|
19883
|
+
if (ts.isStringLiteral(element)) pushUnique(result.hooks, element.text);
|
|
19884
|
+
}
|
|
19885
|
+
}
|
|
19886
|
+
if (property.name.text === "parentHooks") {
|
|
19887
|
+
for (const element of array.elements) {
|
|
19888
|
+
if (!ts.isObjectLiteralExpression(element)) continue;
|
|
19889
|
+
let hook;
|
|
19890
|
+
let reason;
|
|
19891
|
+
let stage;
|
|
19892
|
+
for (const requirement of element.properties) {
|
|
19893
|
+
if (ts.isPropertyAssignment(requirement) && ts.isIdentifier(requirement.name) && ts.isStringLiteral(requirement.initializer)) {
|
|
19894
|
+
if (requirement.name.text === "hook") hook = requirement.initializer.text;
|
|
19895
|
+
if (requirement.name.text === "reason") reason = requirement.initializer.text;
|
|
19896
|
+
if (requirement.name.text === "stage" && (requirement.initializer.text === "before_parent" || requirement.initializer.text === "after_parent")) {
|
|
19897
|
+
stage = requirement.initializer.text;
|
|
19898
|
+
}
|
|
19899
|
+
}
|
|
19900
|
+
}
|
|
19901
|
+
if (hook) {
|
|
19902
|
+
pushUnique(result.parentHooks, hook);
|
|
19903
|
+
if (reason) result.parentHookRequirements.push({ hook, reason, stage });
|
|
19904
|
+
}
|
|
19905
|
+
}
|
|
19906
|
+
}
|
|
19907
|
+
}
|
|
19908
|
+
}
|
|
19909
|
+
ts.forEachChild(node, visit);
|
|
19910
|
+
}
|
|
19911
|
+
visit(sourceFile);
|
|
19912
|
+
return result;
|
|
19913
|
+
}
|
|
19914
|
+
async function extractPromptHooks(sourceCode) {
|
|
19915
|
+
const ts = await loadTypeScript();
|
|
19916
|
+
const sourceFile = ts.createSourceFile(
|
|
19917
|
+
"prompt.ts",
|
|
19918
|
+
sourceCode,
|
|
19919
|
+
ts.ScriptTarget.ESNext,
|
|
19920
|
+
true
|
|
19921
|
+
);
|
|
19922
|
+
const hooks = [];
|
|
19923
|
+
function visit(node) {
|
|
19924
|
+
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "definePrompt" && node.arguments.length > 0 && ts.isObjectLiteralExpression(node.arguments[0])) {
|
|
19925
|
+
for (const property of node.arguments[0].properties) {
|
|
19926
|
+
if (ts.isPropertyAssignment(property) && ts.isIdentifier(property.name) && property.name.text === "hooks" && ts.isArrayLiteralExpression(property.initializer)) {
|
|
19927
|
+
for (const element of property.initializer.elements) {
|
|
19928
|
+
if (ts.isStringLiteral(element) && !hooks.includes(element.text)) {
|
|
19929
|
+
hooks.push(element.text);
|
|
19930
|
+
}
|
|
19931
|
+
}
|
|
19932
|
+
}
|
|
19933
|
+
}
|
|
19934
|
+
}
|
|
19935
|
+
ts.forEachChild(node, visit);
|
|
19936
|
+
}
|
|
19937
|
+
visit(sourceFile);
|
|
19938
|
+
return hooks;
|
|
19939
|
+
}
|
|
19245
19940
|
async function extractAgentDescription(sourceCode) {
|
|
19246
19941
|
const ts = await loadTypeScript();
|
|
19247
19942
|
const sourceFile = ts.createSourceFile(
|
|
@@ -19481,6 +20176,13 @@ var PackingService = class {
|
|
|
19481
20176
|
});
|
|
19482
20177
|
const agentSource = fs9.readFileSync(agentFilePath, "utf-8");
|
|
19483
20178
|
const agentPrompts = await extractAgentPrompts(agentSource);
|
|
20179
|
+
const agentHooks = await extractAgentHooks(agentSource);
|
|
20180
|
+
for (const hookId of agentHooks.hooks) {
|
|
20181
|
+
await this.analyzeHook(hookId, agentsDir, analysis, false, `agent:${agentName}`);
|
|
20182
|
+
}
|
|
20183
|
+
for (const hookId of agentHooks.parentHooks) {
|
|
20184
|
+
await this.analyzeHook(hookId, agentsDir, analysis, true, `agent:${agentName}`);
|
|
20185
|
+
}
|
|
19484
20186
|
if (agentPrompts.sideA) {
|
|
19485
20187
|
analysis.primaryPrompt = agentPrompts.sideA;
|
|
19486
20188
|
await this.analyzePrompt(agentPrompts.sideA, agentsDir, analysis, /* @__PURE__ */ new Set(), `agent:${agentName}`);
|
|
@@ -19683,6 +20385,9 @@ var PackingService = class {
|
|
|
19683
20385
|
}
|
|
19684
20386
|
visited.add(`prompt:${promptName}`);
|
|
19685
20387
|
const promptSource = fs9.readFileSync(promptFilePath, "utf-8");
|
|
20388
|
+
for (const hookId of await extractPromptHooks(promptSource)) {
|
|
20389
|
+
await this.analyzeHook(hookId, agentsDir, analysis, false, thisKey);
|
|
20390
|
+
}
|
|
19686
20391
|
const modelName = await extractPromptModel(promptSource);
|
|
19687
20392
|
if (modelName) {
|
|
19688
20393
|
await this.analyzeModel(modelName, agentsDir, analysis, visited, thisKey);
|
|
@@ -19767,6 +20472,13 @@ var PackingService = class {
|
|
|
19767
20472
|
visited.add(`agent:${agentName}`);
|
|
19768
20473
|
const agentSource = fs9.readFileSync(agentFilePath, "utf-8");
|
|
19769
20474
|
const agentPrompts = await extractAgentPrompts(agentSource);
|
|
20475
|
+
const agentHooks = await extractAgentHooks(agentSource);
|
|
20476
|
+
for (const hookId of agentHooks.hooks) {
|
|
20477
|
+
await this.analyzeHook(hookId, agentsDir, analysis, false, thisKey);
|
|
20478
|
+
}
|
|
20479
|
+
for (const hookId of agentHooks.parentHooks) {
|
|
20480
|
+
await this.analyzeHook(hookId, agentsDir, analysis, true, thisKey);
|
|
20481
|
+
}
|
|
19770
20482
|
if (agentPrompts.sideA) {
|
|
19771
20483
|
await this.analyzePrompt(agentPrompts.sideA, agentsDir, analysis, visited, thisKey);
|
|
19772
20484
|
}
|
|
@@ -19774,6 +20486,27 @@ var PackingService = class {
|
|
|
19774
20486
|
await this.analyzePrompt(agentPrompts.sideB, agentsDir, analysis, visited, thisKey);
|
|
19775
20487
|
}
|
|
19776
20488
|
}
|
|
20489
|
+
/** Add a hook referenced by an agent or prompt to the packed graph. */
|
|
20490
|
+
async analyzeHook(hookId, agentsDir, analysis, required, parentKey) {
|
|
20491
|
+
const hookFilePath = await this.findFile(path9.join(agentsDir, "hooks"), hookId);
|
|
20492
|
+
if (!hookFilePath) {
|
|
20493
|
+
const message = `Hook file not found for ID: ${hookId}`;
|
|
20494
|
+
if (required) analysis.errors.push(message);
|
|
20495
|
+
else analysis.warnings.push(message);
|
|
20496
|
+
return;
|
|
20497
|
+
}
|
|
20498
|
+
if (!analysis.constituents.hooks.some(
|
|
20499
|
+
(hook) => hook.name === hookId && hook.parentKey === parentKey
|
|
20500
|
+
)) {
|
|
20501
|
+
analysis.constituents.hooks.push({
|
|
20502
|
+
name: hookId,
|
|
20503
|
+
filePath: hookFilePath,
|
|
20504
|
+
discoveredVia: "static",
|
|
20505
|
+
sharedWith: [],
|
|
20506
|
+
parentKey
|
|
20507
|
+
});
|
|
20508
|
+
}
|
|
20509
|
+
}
|
|
19777
20510
|
/**
|
|
19778
20511
|
* Analyze a model and its fallbacks.
|
|
19779
20512
|
*/
|
|
@@ -19908,11 +20641,17 @@ var PackingService = class {
|
|
|
19908
20641
|
} = options;
|
|
19909
20642
|
const finalPackageName = packageName || packageId;
|
|
19910
20643
|
const packedAt = Date.now();
|
|
20644
|
+
const entryAgentFile = await this.findFile(
|
|
20645
|
+
path9.join(rootDir, "agents", "agents"),
|
|
20646
|
+
agentName
|
|
20647
|
+
);
|
|
20648
|
+
const entryParentHooks = entryAgentFile ? (await extractAgentHooks(fs9.readFileSync(entryAgentFile, "utf-8"))).parentHookRequirements : [];
|
|
19911
20649
|
const meta = {
|
|
19912
20650
|
packageId,
|
|
19913
20651
|
version,
|
|
19914
20652
|
entryAgents: [agentName],
|
|
19915
|
-
packedAt
|
|
20653
|
+
packedAt,
|
|
20654
|
+
...entryParentHooks.length > 0 ? { parentHooks: { [agentName]: entryParentHooks } } : {}
|
|
19916
20655
|
};
|
|
19917
20656
|
const result = {
|
|
19918
20657
|
success: false,
|
|
@@ -20021,6 +20760,7 @@ var PackingService = class {
|
|
|
20021
20760
|
agentName,
|
|
20022
20761
|
this.deduplicateConstituents(analysis).effects.map((effect) => effect.name),
|
|
20023
20762
|
this.deduplicateConstituents(analysis).threadEndpoints.map((endpoint) => endpoint.name),
|
|
20763
|
+
meta.parentHooks,
|
|
20024
20764
|
externalDeps,
|
|
20025
20765
|
rootDir,
|
|
20026
20766
|
license,
|
|
@@ -20412,7 +21152,7 @@ var PackingService = class {
|
|
|
20412
21152
|
/**
|
|
20413
21153
|
* Generate the package.json file with dependencies.
|
|
20414
21154
|
*/
|
|
20415
|
-
generatePackageJson(packageName, version, agentName, effects, threadEndpoints, externalDeps, rootDir, license, licenseOwner) {
|
|
21155
|
+
generatePackageJson(packageName, version, agentName, effects, threadEndpoints, parentHooks, externalDeps, rootDir, license, licenseOwner) {
|
|
20416
21156
|
const dependencies = {
|
|
20417
21157
|
"@standardagents/spec": this.resolvePackageVersion("@standardagents/spec", rootDir)
|
|
20418
21158
|
};
|
|
@@ -20434,6 +21174,7 @@ var PackingService = class {
|
|
|
20434
21174
|
keywords: ["standardagent"],
|
|
20435
21175
|
standardagent: {
|
|
20436
21176
|
entryAgents: [agentName],
|
|
21177
|
+
...parentHooks ? { parentHooks } : {},
|
|
20437
21178
|
...effects.length > 0 ? { effects } : {},
|
|
20438
21179
|
...threadEndpoints.length > 0 ? { threadEndpoints } : {}
|
|
20439
21180
|
},
|
|
@@ -20727,6 +21468,22 @@ ${license || "See LICENSE file"}
|
|
|
20727
21468
|
return agents;
|
|
20728
21469
|
}
|
|
20729
21470
|
};
|
|
21471
|
+
function validParentHooks(value) {
|
|
21472
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
21473
|
+
return Object.values(value).every((requirements) => {
|
|
21474
|
+
if (!Array.isArray(requirements)) return false;
|
|
21475
|
+
const seen = /* @__PURE__ */ new Set();
|
|
21476
|
+
return requirements.every((requirement) => {
|
|
21477
|
+
if (typeof requirement !== "object" || requirement === null) return false;
|
|
21478
|
+
const item = requirement;
|
|
21479
|
+
if (typeof item.hook !== "string" || !item.hook.trim() || typeof item.reason !== "string" || !item.reason.trim() || item.stage !== void 0 && item.stage !== "before_parent" && item.stage !== "after_parent" || seen.has(item.hook)) {
|
|
21480
|
+
return false;
|
|
21481
|
+
}
|
|
21482
|
+
seen.add(item.hook);
|
|
21483
|
+
return true;
|
|
21484
|
+
});
|
|
21485
|
+
});
|
|
21486
|
+
}
|
|
20730
21487
|
var PackageDiscoveryService = class {
|
|
20731
21488
|
config;
|
|
20732
21489
|
constructor(config) {
|
|
@@ -20822,6 +21579,7 @@ var PackageDiscoveryService = class {
|
|
|
20822
21579
|
}
|
|
20823
21580
|
const effects = Array.isArray(pkgJson.standardagent.effects) && pkgJson.standardagent.effects.every((effectName) => typeof effectName === "string") ? pkgJson.standardagent.effects : void 0;
|
|
20824
21581
|
const threadEndpoints = Array.isArray(pkgJson.standardagent.threadEndpoints) && pkgJson.standardagent.threadEndpoints.every((endpoint) => typeof endpoint === "string") ? pkgJson.standardagent.threadEndpoints : void 0;
|
|
21582
|
+
const parentHooks = validParentHooks(pkgJson.standardagent.parentHooks) ? pkgJson.standardagent.parentHooks : void 0;
|
|
20825
21583
|
return {
|
|
20826
21584
|
packageId: pkgJson.name || pkgName,
|
|
20827
21585
|
version: pkgJson.version || "0.0.0",
|
|
@@ -20830,6 +21588,7 @@ var PackageDiscoveryService = class {
|
|
|
20830
21588
|
entryAgents: pkgJson.standardagent.entryAgents,
|
|
20831
21589
|
...effects ? { effects } : {},
|
|
20832
21590
|
...threadEndpoints ? { threadEndpoints } : {},
|
|
21591
|
+
...parentHooks ? { parentHooks } : {},
|
|
20833
21592
|
description: pkgJson.description
|
|
20834
21593
|
};
|
|
20835
21594
|
} catch (error) {
|
|
@@ -20891,6 +21650,7 @@ var PackageDiscoveryService = class {
|
|
|
20891
21650
|
}
|
|
20892
21651
|
const effects = Array.isArray(pkgJson.standardagent.effects) && pkgJson.standardagent.effects.every((effectName) => typeof effectName === "string") ? pkgJson.standardagent.effects : void 0;
|
|
20893
21652
|
const threadEndpoints = Array.isArray(pkgJson.standardagent.threadEndpoints) && pkgJson.standardagent.threadEndpoints.every((endpoint) => typeof endpoint === "string") ? pkgJson.standardagent.threadEndpoints : void 0;
|
|
21653
|
+
const parentHooks = validParentHooks(pkgJson.standardagent.parentHooks) ? pkgJson.standardagent.parentHooks : void 0;
|
|
20894
21654
|
return {
|
|
20895
21655
|
packageId: pkgJson.name || dirName,
|
|
20896
21656
|
version: pkgJson.version || "0.0.0",
|
|
@@ -20899,6 +21659,7 @@ var PackageDiscoveryService = class {
|
|
|
20899
21659
|
entryAgents: pkgJson.standardagent.entryAgents,
|
|
20900
21660
|
...effects ? { effects } : {},
|
|
20901
21661
|
...threadEndpoints ? { threadEndpoints } : {},
|
|
21662
|
+
...parentHooks ? { parentHooks } : {},
|
|
20902
21663
|
description: pkgJson.description
|
|
20903
21664
|
};
|
|
20904
21665
|
} catch (error) {
|
|
@@ -20927,7 +21688,8 @@ var PackageDiscoveryService = class {
|
|
|
20927
21688
|
const hasValidEntryAgents = Array.isArray(f.entryAgents) && f.entryAgents.length > 0 && f.entryAgents.every((e) => typeof e === "string");
|
|
20928
21689
|
const hasValidEffects = f.effects === void 0 || Array.isArray(f.effects) && f.effects.every((effectName) => typeof effectName === "string");
|
|
20929
21690
|
const hasValidThreadEndpoints = f.threadEndpoints === void 0 || Array.isArray(f.threadEndpoints) && f.threadEndpoints.every((endpoint) => typeof endpoint === "string");
|
|
20930
|
-
|
|
21691
|
+
const hasValidParentHooks = f.parentHooks === void 0 || validParentHooks(f.parentHooks);
|
|
21692
|
+
return hasValidEntryAgents && hasValidEffects && hasValidThreadEndpoints && hasValidParentHooks;
|
|
20931
21693
|
}
|
|
20932
21694
|
/**
|
|
20933
21695
|
* Get a package by ID.
|
|
@@ -22555,13 +23317,13 @@ async function loadRegistryVirtualModule(context) {
|
|
|
22555
23317
|
const absPath = toAbsolutePath(importPath);
|
|
22556
23318
|
return ` "${name}": async () => (await import("${absPath}")).default,`;
|
|
22557
23319
|
}).join("\n");
|
|
22558
|
-
const
|
|
23320
|
+
const projectRoot = process.cwd();
|
|
22559
23321
|
const packedPackages = [];
|
|
22560
|
-
|
|
22561
|
-
|
|
22562
|
-
|
|
22563
|
-
|
|
22564
|
-
|
|
23322
|
+
{
|
|
23323
|
+
const packageDirs = discoverStandardAgentPackageDirectories(projectRoot);
|
|
23324
|
+
console.log(`[vite-plugin-agent] Found Standard Agent package dirs: ${packageDirs.map((pkg) => pkg.path).join(", ")}`);
|
|
23325
|
+
for (const discovered of packageDirs) {
|
|
23326
|
+
const pkgPath = discovered.path;
|
|
22565
23327
|
const pkgJsonPath = path9__default.join(pkgPath, "package.json");
|
|
22566
23328
|
if (fs9__default.existsSync(pkgJsonPath)) {
|
|
22567
23329
|
try {
|
|
@@ -22575,6 +23337,7 @@ async function loadRegistryVirtualModule(context) {
|
|
|
22575
23337
|
const pkg = {
|
|
22576
23338
|
packageId: pkgJson.name,
|
|
22577
23339
|
version: pkgJson.version,
|
|
23340
|
+
source: discovered.source,
|
|
22578
23341
|
entryAgents: pkgJson.standardagent.entryAgents || [],
|
|
22579
23342
|
items: {
|
|
22580
23343
|
agents: scanPackedDistDirectory(pkgPath, outputDir, "agents"),
|
|
@@ -22593,15 +23356,13 @@ async function loadRegistryVirtualModule(context) {
|
|
|
22593
23356
|
}
|
|
22594
23357
|
}
|
|
22595
23358
|
}
|
|
22596
|
-
} else {
|
|
22597
|
-
console.log(`[vite-plugin-agent] Packed directory does not exist: ${packedDir}`);
|
|
22598
23359
|
}
|
|
22599
23360
|
console.log(`[vite-plugin-agent] Total packed packages found: ${packedPackages.length}`);
|
|
22600
23361
|
const packagesCode = packedPackages.map((pkg) => {
|
|
22601
23362
|
const signature = JSON.stringify({
|
|
22602
23363
|
packageId: pkg.packageId,
|
|
22603
23364
|
version: pkg.version,
|
|
22604
|
-
source:
|
|
23365
|
+
source: pkg.source,
|
|
22605
23366
|
packedAt: Date.now()
|
|
22606
23367
|
});
|
|
22607
23368
|
const genLoaders = (items) => items.map(
|
|
@@ -22700,9 +23461,9 @@ async function loadRoutesVirtualModule(context) {
|
|
|
22700
23461
|
);`;
|
|
22701
23462
|
}).join("\n");
|
|
22702
23463
|
const packedThreadRoutes = [];
|
|
22703
|
-
const
|
|
22704
|
-
const
|
|
22705
|
-
|
|
23464
|
+
const packedPackageDirs = discoverStandardAgentPackageDirectories(process.cwd());
|
|
23465
|
+
for (const discovered of packedPackageDirs) {
|
|
23466
|
+
const packagePath = discovered.path;
|
|
22706
23467
|
const packageJsonPath = path9__default.join(packagePath, "package.json");
|
|
22707
23468
|
if (!fs9__default.existsSync(packageJsonPath)) {
|
|
22708
23469
|
continue;
|
|
@@ -26175,701 +26936,388 @@ var migration48 = {
|
|
|
26175
26936
|
deleted_at INTEGER,
|
|
26176
26937
|
permissions TEXT
|
|
26177
26938
|
)
|
|
26178
|
-
`);
|
|
26179
|
-
sql.exec(`
|
|
26180
|
-
INSERT INTO users (
|
|
26181
|
-
id, username, password_hash, role, created_at, updated_at,
|
|
26182
|
-
platform_user_id, email, display_name, avatar_url, instance_role,
|
|
26183
|
-
source, replica_active, replica_updated_at, deleted_at, permissions
|
|
26184
|
-
)
|
|
26185
|
-
SELECT
|
|
26186
|
-
id, username, password_hash, role, created_at, updated_at,
|
|
26187
|
-
platform_user_id, email, display_name, avatar_url, instance_role,
|
|
26188
|
-
source, replica_active, replica_updated_at, deleted_at, permissions
|
|
26189
|
-
FROM users_0012_old
|
|
26190
|
-
`);
|
|
26191
|
-
sql.exec(`DROP TABLE users_0012_old`);
|
|
26192
|
-
sql.exec(`CREATE INDEX idx_users_username ON users(username)`);
|
|
26193
|
-
sql.exec(`CREATE INDEX idx_users_role ON users(role)`);
|
|
26194
|
-
sql.exec(`CREATE INDEX idx_users_platform_user_id ON users(platform_user_id)`);
|
|
26195
|
-
sql.exec(`CREATE INDEX idx_users_replica_active ON users(replica_active)`);
|
|
26196
|
-
sql.exec(`CREATE INDEX idx_users_instance_role ON users(instance_role)`);
|
|
26197
|
-
sql.exec(`
|
|
26198
|
-
CREATE TABLE oauth_accounts (
|
|
26199
|
-
id TEXT PRIMARY KEY NOT NULL,
|
|
26200
|
-
user_id TEXT NOT NULL,
|
|
26201
|
-
provider TEXT NOT NULL CHECK (provider IN ('github', 'google')),
|
|
26202
|
-
provider_user_id TEXT NOT NULL,
|
|
26203
|
-
provider_username TEXT,
|
|
26204
|
-
created_at INTEGER DEFAULT (strftime('%s', 'now')),
|
|
26205
|
-
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
|
26206
|
-
)
|
|
26207
|
-
`);
|
|
26208
|
-
sql.exec(`INSERT INTO oauth_accounts SELECT * FROM oauth_accounts_0012_backup`);
|
|
26209
|
-
sql.exec(`CREATE UNIQUE INDEX idx_oauth_accounts_provider ON oauth_accounts(provider, provider_user_id)`);
|
|
26210
|
-
sql.exec(`CREATE INDEX idx_oauth_accounts_user_id ON oauth_accounts(user_id)`);
|
|
26211
|
-
sql.exec(`
|
|
26212
|
-
CREATE TABLE api_keys (
|
|
26213
|
-
id TEXT PRIMARY KEY NOT NULL,
|
|
26214
|
-
name TEXT NOT NULL,
|
|
26215
|
-
key_hash TEXT NOT NULL,
|
|
26216
|
-
key_prefix TEXT NOT NULL,
|
|
26217
|
-
last_five TEXT NOT NULL,
|
|
26218
|
-
user_id TEXT NOT NULL,
|
|
26219
|
-
created_at INTEGER DEFAULT (strftime('%s', 'now')),
|
|
26220
|
-
last_used_at INTEGER,
|
|
26221
|
-
platform_key_id TEXT,
|
|
26222
|
-
scope TEXT,
|
|
26223
|
-
source TEXT NOT NULL DEFAULT 'local' CHECK (source IN ('local', 'standard_agents')),
|
|
26224
|
-
replica_active INTEGER NOT NULL DEFAULT 1,
|
|
26225
|
-
replica_updated_at INTEGER,
|
|
26226
|
-
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
|
26227
|
-
)
|
|
26228
|
-
`);
|
|
26229
|
-
sql.exec(`INSERT INTO api_keys SELECT * FROM api_keys_0012_backup`);
|
|
26230
|
-
sql.exec(`CREATE INDEX idx_api_keys_key_hash ON api_keys(key_hash)`);
|
|
26231
|
-
sql.exec(`CREATE INDEX idx_api_keys_user_id ON api_keys(user_id)`);
|
|
26232
|
-
sql.exec(`CREATE INDEX idx_api_keys_key_prefix ON api_keys(key_prefix)`);
|
|
26233
|
-
sql.exec(`CREATE INDEX idx_api_keys_platform_key_id ON api_keys(platform_key_id)`);
|
|
26234
|
-
sql.exec(`CREATE INDEX idx_api_keys_replica_active ON api_keys(replica_active)`);
|
|
26235
|
-
sql.exec(`
|
|
26236
|
-
CREATE TABLE sessions (
|
|
26237
|
-
id TEXT PRIMARY KEY NOT NULL,
|
|
26238
|
-
user_id TEXT NOT NULL,
|
|
26239
|
-
token_hash TEXT NOT NULL,
|
|
26240
|
-
expires_at INTEGER NOT NULL,
|
|
26241
|
-
created_at INTEGER DEFAULT (strftime('%s', 'now')),
|
|
26242
|
-
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
|
26243
|
-
)
|
|
26244
|
-
`);
|
|
26245
|
-
sql.exec(`INSERT INTO sessions SELECT * FROM sessions_0012_backup`);
|
|
26246
|
-
sql.exec(`CREATE INDEX idx_sessions_token_hash ON sessions(token_hash)`);
|
|
26247
|
-
sql.exec(`CREATE INDEX idx_sessions_user_id ON sessions(user_id)`);
|
|
26248
|
-
sql.exec(`CREATE INDEX idx_sessions_expires_at ON sessions(expires_at)`);
|
|
26249
|
-
sql.exec(`DROP TABLE oauth_accounts_0012_backup`);
|
|
26250
|
-
sql.exec(`DROP TABLE api_keys_0012_backup`);
|
|
26251
|
-
sql.exec(`DROP TABLE sessions_0012_backup`);
|
|
26252
|
-
sql.exec(`
|
|
26253
|
-
INSERT OR REPLACE INTO _metadata (key, value) VALUES ('schema_version', '12')
|
|
26254
|
-
`);
|
|
26255
|
-
}
|
|
26256
|
-
};
|
|
26257
|
-
|
|
26258
|
-
// src/durable-objects/agentbuilder-migrations/0013_add_thread_activity.ts
|
|
26259
|
-
var migration49 = {
|
|
26260
|
-
version: 13,
|
|
26261
|
-
async up(sql) {
|
|
26262
|
-
sql.exec(`ALTER TABLE threads ADD COLUMN last_activity_at INTEGER`);
|
|
26263
|
-
sql.exec(`ALTER TABLE threads ADD COLUMN executing_since INTEGER`);
|
|
26264
|
-
sql.exec(
|
|
26265
|
-
`CREATE INDEX IF NOT EXISTS idx_threads_last_activity_at ON threads(last_activity_at)`
|
|
26266
|
-
);
|
|
26267
|
-
sql.exec(`UPDATE threads SET last_activity_at = created_at`);
|
|
26268
|
-
sql.exec(`
|
|
26269
|
-
INSERT OR REPLACE INTO _metadata (key, value) VALUES ('schema_version', '13')
|
|
26270
|
-
`);
|
|
26271
|
-
}
|
|
26272
|
-
};
|
|
26273
|
-
|
|
26274
|
-
// src/durable-objects/agentbuilder-migrations/0014_thread_activity_scale.ts
|
|
26275
|
-
var migration50 = {
|
|
26276
|
-
version: 14,
|
|
26277
|
-
async up(sql) {
|
|
26278
|
-
sql.exec(`ALTER TABLE threads ADD COLUMN last_message_preview TEXT`);
|
|
26279
|
-
sql.exec(
|
|
26280
|
-
`CREATE INDEX IF NOT EXISTS idx_threads_executing_since
|
|
26281
|
-
ON threads(executing_since) WHERE executing_since IS NOT NULL`
|
|
26282
|
-
);
|
|
26283
|
-
sql.exec(
|
|
26284
|
-
`UPDATE threads SET last_activity_at = created_at WHERE last_activity_at IS NULL`
|
|
26285
|
-
);
|
|
26286
|
-
sql.exec(`
|
|
26287
|
-
INSERT OR REPLACE INTO _metadata (key, value) VALUES ('schema_version', '14')
|
|
26288
|
-
`);
|
|
26289
|
-
}
|
|
26290
|
-
};
|
|
26291
|
-
|
|
26292
|
-
// src/durable-objects/agentbuilder-migrations/0015_clear_envelope_previews.ts
|
|
26293
|
-
var migration51 = {
|
|
26294
|
-
version: 15,
|
|
26295
|
-
async up(sql) {
|
|
26296
|
-
sql.exec(
|
|
26297
|
-
`UPDATE threads SET last_message_preview = NULL
|
|
26298
|
-
WHERE last_message_preview LIKE 'Subagent (reference: %'`
|
|
26299
|
-
);
|
|
26300
|
-
sql.exec(`
|
|
26301
|
-
INSERT OR REPLACE INTO _metadata (key, value) VALUES ('schema_version', '15')
|
|
26302
|
-
`);
|
|
26303
|
-
}
|
|
26304
|
-
};
|
|
26305
|
-
|
|
26306
|
-
// src/durable-objects/agentbuilder-migrations/0016_add_origin_agent.ts
|
|
26307
|
-
var migration52 = {
|
|
26308
|
-
version: 16,
|
|
26309
|
-
async up(sql) {
|
|
26310
|
-
sql.exec(`ALTER TABLE threads ADD COLUMN origin_agent_name TEXT`);
|
|
26311
|
-
sql.exec(
|
|
26312
|
-
`CREATE INDEX IF NOT EXISTS idx_threads_origin_agent_name ON threads(origin_agent_name)`
|
|
26313
|
-
);
|
|
26314
|
-
sql.exec(`UPDATE threads SET origin_agent_name = agent_name`);
|
|
26315
|
-
sql.exec(`
|
|
26316
|
-
INSERT OR REPLACE INTO _metadata (key, value) VALUES ('schema_version', '16')
|
|
26317
|
-
`);
|
|
26318
|
-
}
|
|
26319
|
-
};
|
|
26320
|
-
|
|
26321
|
-
// src/durable-objects/agentbuilder-migrations/0017_add_thread_message_recency.ts
|
|
26322
|
-
var migration53 = {
|
|
26323
|
-
version: 17,
|
|
26324
|
-
async up(sql) {
|
|
26325
|
-
sql.exec(`ALTER TABLE threads ADD COLUMN last_message_at INTEGER`);
|
|
26326
|
-
sql.exec(`UPDATE threads SET last_message_at = created_at`);
|
|
26327
|
-
sql.exec(`
|
|
26328
|
-
INSERT OR REPLACE INTO _metadata (key, value) VALUES ('schema_version', '17')
|
|
26329
|
-
`);
|
|
26330
|
-
}
|
|
26331
|
-
};
|
|
26332
|
-
|
|
26333
|
-
// src/durable-objects/agentbuilder-migrations/0018_auth_security.ts
|
|
26334
|
-
var migration54 = {
|
|
26335
|
-
version: 18,
|
|
26336
|
-
async up(sql) {
|
|
26337
|
-
sql.exec(`
|
|
26338
|
-
CREATE TABLE IF NOT EXISTS super_admin_sessions (
|
|
26339
|
-
token_hash TEXT PRIMARY KEY,
|
|
26340
|
-
created_at INTEGER NOT NULL,
|
|
26341
|
-
expires_at INTEGER NOT NULL
|
|
26342
|
-
)
|
|
26343
|
-
`);
|
|
26344
|
-
sql.exec(`
|
|
26345
|
-
CREATE INDEX IF NOT EXISTS idx_super_admin_sessions_expires
|
|
26346
|
-
ON super_admin_sessions(expires_at)
|
|
26347
|
-
`);
|
|
26348
|
-
sql.exec(`
|
|
26349
|
-
CREATE TABLE IF NOT EXISTS auth_rate_limits (
|
|
26350
|
-
bucket_key TEXT PRIMARY KEY,
|
|
26351
|
-
attempts INTEGER NOT NULL,
|
|
26352
|
-
reset_at INTEGER NOT NULL
|
|
26353
|
-
)
|
|
26354
|
-
`);
|
|
26355
|
-
sql.exec(`
|
|
26356
|
-
CREATE INDEX IF NOT EXISTS idx_auth_rate_limits_reset
|
|
26357
|
-
ON auth_rate_limits(reset_at)
|
|
26358
|
-
`);
|
|
26359
|
-
sql.exec(`
|
|
26360
|
-
INSERT OR REPLACE INTO _metadata (key, value) VALUES ('schema_version', '18')
|
|
26361
|
-
`);
|
|
26362
|
-
}
|
|
26363
|
-
};
|
|
26364
|
-
|
|
26365
|
-
// src/durable-objects/agentbuilder-migrations/0019_scope_skills.ts
|
|
26366
|
-
var migration55 = {
|
|
26367
|
-
version: 19,
|
|
26368
|
-
async up(sql) {
|
|
26369
|
-
sql.exec(`
|
|
26370
|
-
CREATE TABLE skills_0019 (
|
|
26371
|
-
owner_id TEXT NOT NULL,
|
|
26372
|
-
name TEXT NOT NULL,
|
|
26373
|
-
description TEXT NOT NULL,
|
|
26374
|
-
version TEXT,
|
|
26375
|
-
enabled INTEGER NOT NULL DEFAULT 1,
|
|
26376
|
-
shared INTEGER NOT NULL DEFAULT 0,
|
|
26377
|
-
created_at INTEGER DEFAULT (strftime('%s', 'now')),
|
|
26378
|
-
updated_at INTEGER DEFAULT (strftime('%s', 'now')),
|
|
26379
|
-
PRIMARY KEY (owner_id, name)
|
|
26380
|
-
)
|
|
26381
|
-
`);
|
|
26382
|
-
sql.exec(`
|
|
26383
|
-
INSERT INTO skills_0019 (
|
|
26384
|
-
owner_id, name, description, version, enabled, shared, created_at, updated_at
|
|
26385
|
-
)
|
|
26386
|
-
SELECT '__instance_shared__', name, description, version, enabled, 1, created_at, updated_at
|
|
26387
|
-
FROM skills
|
|
26388
|
-
`);
|
|
26389
|
-
sql.exec(`
|
|
26390
|
-
CREATE TABLE skill_files_0019 (
|
|
26391
|
-
owner_id TEXT NOT NULL,
|
|
26392
|
-
skill_name TEXT NOT NULL,
|
|
26393
|
-
path TEXT NOT NULL,
|
|
26394
|
-
content TEXT NOT NULL,
|
|
26395
|
-
size INTEGER NOT NULL,
|
|
26396
|
-
PRIMARY KEY (owner_id, skill_name, path),
|
|
26397
|
-
FOREIGN KEY (owner_id, skill_name) REFERENCES skills_0019(owner_id, name) ON DELETE CASCADE
|
|
26398
|
-
)
|
|
26399
|
-
`);
|
|
26400
|
-
sql.exec(`
|
|
26401
|
-
INSERT INTO skill_files_0019 (owner_id, skill_name, path, content, size)
|
|
26402
|
-
SELECT '__instance_shared__', skill_name, path, content, size FROM skill_files
|
|
26403
|
-
`);
|
|
26404
|
-
sql.exec(`DROP TABLE skill_files`);
|
|
26405
|
-
sql.exec(`DROP TABLE skills`);
|
|
26406
|
-
sql.exec(`ALTER TABLE skills_0019 RENAME TO skills`);
|
|
26407
|
-
sql.exec(`ALTER TABLE skill_files_0019 RENAME TO skill_files`);
|
|
26408
|
-
sql.exec(`CREATE INDEX idx_skills_owner_enabled ON skills(owner_id, enabled)`);
|
|
26409
|
-
sql.exec(`CREATE INDEX idx_skills_shared_enabled ON skills(shared, enabled)`);
|
|
26410
|
-
sql.exec(`CREATE INDEX idx_skill_files_skill ON skill_files(owner_id, skill_name)`);
|
|
26411
|
-
sql.exec(`INSERT OR REPLACE INTO _metadata (key, value) VALUES ('schema_version', '19')`);
|
|
26412
|
-
}
|
|
26413
|
-
};
|
|
26414
|
-
|
|
26415
|
-
// src/durable-objects/agentbuilder-migrations/0020_websocket_tickets.ts
|
|
26416
|
-
var migration56 = {
|
|
26417
|
-
version: 20,
|
|
26418
|
-
async up(sql) {
|
|
26939
|
+
`);
|
|
26419
26940
|
sql.exec(`
|
|
26420
|
-
|
|
26421
|
-
|
|
26422
|
-
|
|
26423
|
-
|
|
26424
|
-
created_at INTEGER NOT NULL,
|
|
26425
|
-
expires_at INTEGER NOT NULL
|
|
26941
|
+
INSERT INTO users (
|
|
26942
|
+
id, username, password_hash, role, created_at, updated_at,
|
|
26943
|
+
platform_user_id, email, display_name, avatar_url, instance_role,
|
|
26944
|
+
source, replica_active, replica_updated_at, deleted_at, permissions
|
|
26426
26945
|
)
|
|
26946
|
+
SELECT
|
|
26947
|
+
id, username, password_hash, role, created_at, updated_at,
|
|
26948
|
+
platform_user_id, email, display_name, avatar_url, instance_role,
|
|
26949
|
+
source, replica_active, replica_updated_at, deleted_at, permissions
|
|
26950
|
+
FROM users_0012_old
|
|
26427
26951
|
`);
|
|
26952
|
+
sql.exec(`DROP TABLE users_0012_old`);
|
|
26953
|
+
sql.exec(`CREATE INDEX idx_users_username ON users(username)`);
|
|
26954
|
+
sql.exec(`CREATE INDEX idx_users_role ON users(role)`);
|
|
26955
|
+
sql.exec(`CREATE INDEX idx_users_platform_user_id ON users(platform_user_id)`);
|
|
26956
|
+
sql.exec(`CREATE INDEX idx_users_replica_active ON users(replica_active)`);
|
|
26957
|
+
sql.exec(`CREATE INDEX idx_users_instance_role ON users(instance_role)`);
|
|
26428
26958
|
sql.exec(`
|
|
26429
|
-
CREATE
|
|
26430
|
-
|
|
26959
|
+
CREATE TABLE oauth_accounts (
|
|
26960
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
26961
|
+
user_id TEXT NOT NULL,
|
|
26962
|
+
provider TEXT NOT NULL CHECK (provider IN ('github', 'google')),
|
|
26963
|
+
provider_user_id TEXT NOT NULL,
|
|
26964
|
+
provider_username TEXT,
|
|
26965
|
+
created_at INTEGER DEFAULT (strftime('%s', 'now')),
|
|
26966
|
+
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
|
26967
|
+
)
|
|
26431
26968
|
`);
|
|
26432
|
-
sql.exec(`INSERT
|
|
26433
|
-
|
|
26434
|
-
|
|
26435
|
-
|
|
26436
|
-
// src/durable-objects/agentbuilder-migrations/0021_platform_handoff_jtis.ts
|
|
26437
|
-
var migration57 = {
|
|
26438
|
-
version: 21,
|
|
26439
|
-
async up(sql) {
|
|
26969
|
+
sql.exec(`INSERT INTO oauth_accounts SELECT * FROM oauth_accounts_0012_backup`);
|
|
26970
|
+
sql.exec(`CREATE UNIQUE INDEX idx_oauth_accounts_provider ON oauth_accounts(provider, provider_user_id)`);
|
|
26971
|
+
sql.exec(`CREATE INDEX idx_oauth_accounts_user_id ON oauth_accounts(user_id)`);
|
|
26440
26972
|
sql.exec(`
|
|
26441
|
-
CREATE TABLE
|
|
26442
|
-
|
|
26443
|
-
|
|
26444
|
-
|
|
26973
|
+
CREATE TABLE api_keys (
|
|
26974
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
26975
|
+
name TEXT NOT NULL,
|
|
26976
|
+
key_hash TEXT NOT NULL,
|
|
26977
|
+
key_prefix TEXT NOT NULL,
|
|
26978
|
+
last_five TEXT NOT NULL,
|
|
26979
|
+
user_id TEXT NOT NULL,
|
|
26980
|
+
created_at INTEGER DEFAULT (strftime('%s', 'now')),
|
|
26981
|
+
last_used_at INTEGER,
|
|
26982
|
+
platform_key_id TEXT,
|
|
26983
|
+
scope TEXT,
|
|
26984
|
+
source TEXT NOT NULL DEFAULT 'local' CHECK (source IN ('local', 'standard_agents')),
|
|
26985
|
+
replica_active INTEGER NOT NULL DEFAULT 1,
|
|
26986
|
+
replica_updated_at INTEGER,
|
|
26987
|
+
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
|
26445
26988
|
)
|
|
26446
26989
|
`);
|
|
26990
|
+
sql.exec(`INSERT INTO api_keys SELECT * FROM api_keys_0012_backup`);
|
|
26991
|
+
sql.exec(`CREATE INDEX idx_api_keys_key_hash ON api_keys(key_hash)`);
|
|
26992
|
+
sql.exec(`CREATE INDEX idx_api_keys_user_id ON api_keys(user_id)`);
|
|
26993
|
+
sql.exec(`CREATE INDEX idx_api_keys_key_prefix ON api_keys(key_prefix)`);
|
|
26994
|
+
sql.exec(`CREATE INDEX idx_api_keys_platform_key_id ON api_keys(platform_key_id)`);
|
|
26995
|
+
sql.exec(`CREATE INDEX idx_api_keys_replica_active ON api_keys(replica_active)`);
|
|
26447
26996
|
sql.exec(`
|
|
26448
|
-
CREATE
|
|
26449
|
-
|
|
26997
|
+
CREATE TABLE sessions (
|
|
26998
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
26999
|
+
user_id TEXT NOT NULL,
|
|
27000
|
+
token_hash TEXT NOT NULL,
|
|
27001
|
+
expires_at INTEGER NOT NULL,
|
|
27002
|
+
created_at INTEGER DEFAULT (strftime('%s', 'now')),
|
|
27003
|
+
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
|
27004
|
+
)
|
|
27005
|
+
`);
|
|
27006
|
+
sql.exec(`INSERT INTO sessions SELECT * FROM sessions_0012_backup`);
|
|
27007
|
+
sql.exec(`CREATE INDEX idx_sessions_token_hash ON sessions(token_hash)`);
|
|
27008
|
+
sql.exec(`CREATE INDEX idx_sessions_user_id ON sessions(user_id)`);
|
|
27009
|
+
sql.exec(`CREATE INDEX idx_sessions_expires_at ON sessions(expires_at)`);
|
|
27010
|
+
sql.exec(`DROP TABLE oauth_accounts_0012_backup`);
|
|
27011
|
+
sql.exec(`DROP TABLE api_keys_0012_backup`);
|
|
27012
|
+
sql.exec(`DROP TABLE sessions_0012_backup`);
|
|
27013
|
+
sql.exec(`
|
|
27014
|
+
INSERT OR REPLACE INTO _metadata (key, value) VALUES ('schema_version', '12')
|
|
26450
27015
|
`);
|
|
26451
|
-
sql.exec(`INSERT OR REPLACE INTO _metadata (key, value) VALUES ('schema_version', '21')`);
|
|
26452
|
-
}
|
|
26453
|
-
};
|
|
26454
|
-
|
|
26455
|
-
// src/durable-objects/agentbuilder-migrations/index.ts
|
|
26456
|
-
var migrations2 = [migration37, migration38, migration39, migration40, migration41, migration42, migration43, migration44, migration45, migration46, migration47, migration48, migration49, migration50, migration51, migration52, migration53, migration54, migration55, migration56, migration57];
|
|
26457
|
-
var LATEST_SCHEMA_VERSION2 = migrations2.reduce(
|
|
26458
|
-
(max, migration58) => Math.max(max, migration58.version),
|
|
26459
|
-
0
|
|
26460
|
-
);
|
|
26461
|
-
|
|
26462
|
-
// src/utils/crypto.ts
|
|
26463
|
-
var CryptoUtil = class {
|
|
26464
|
-
static algorithm = "aes-256-gcm";
|
|
26465
|
-
/**
|
|
26466
|
-
* Encrypt a string value
|
|
26467
|
-
*/
|
|
26468
|
-
static async encrypt(text, key) {
|
|
26469
|
-
const encoder = new TextEncoder();
|
|
26470
|
-
const data = encoder.encode(text);
|
|
26471
|
-
const cryptoKey = await crypto.subtle.importKey(
|
|
26472
|
-
"raw",
|
|
26473
|
-
hexToBuffer(key),
|
|
26474
|
-
{ name: "AES-GCM" },
|
|
26475
|
-
false,
|
|
26476
|
-
["encrypt"]
|
|
26477
|
-
);
|
|
26478
|
-
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
26479
|
-
const encrypted = await crypto.subtle.encrypt(
|
|
26480
|
-
{
|
|
26481
|
-
name: "AES-GCM",
|
|
26482
|
-
iv
|
|
26483
|
-
},
|
|
26484
|
-
cryptoKey,
|
|
26485
|
-
data
|
|
26486
|
-
);
|
|
26487
|
-
const combined = new Uint8Array(iv.length + encrypted.byteLength);
|
|
26488
|
-
combined.set(iv);
|
|
26489
|
-
combined.set(new Uint8Array(encrypted), iv.length);
|
|
26490
|
-
return bufferToBase64(combined);
|
|
26491
|
-
}
|
|
26492
|
-
/**
|
|
26493
|
-
* Decrypt a string value
|
|
26494
|
-
*/
|
|
26495
|
-
static async decrypt(encryptedText, key) {
|
|
26496
|
-
const combined = base64ToBuffer2(encryptedText);
|
|
26497
|
-
const iv = combined.slice(0, 12);
|
|
26498
|
-
const encrypted = combined.slice(12);
|
|
26499
|
-
const cryptoKey = await crypto.subtle.importKey(
|
|
26500
|
-
"raw",
|
|
26501
|
-
hexToBuffer(key),
|
|
26502
|
-
{ name: "AES-GCM" },
|
|
26503
|
-
false,
|
|
26504
|
-
["decrypt"]
|
|
26505
|
-
);
|
|
26506
|
-
const decrypted = await crypto.subtle.decrypt(
|
|
26507
|
-
{
|
|
26508
|
-
name: "AES-GCM",
|
|
26509
|
-
iv
|
|
26510
|
-
},
|
|
26511
|
-
cryptoKey,
|
|
26512
|
-
encrypted
|
|
26513
|
-
);
|
|
26514
|
-
const decoder = new TextDecoder();
|
|
26515
|
-
return decoder.decode(decrypted);
|
|
26516
|
-
}
|
|
26517
|
-
};
|
|
26518
|
-
function hexToBuffer(hex) {
|
|
26519
|
-
const bytes = new Uint8Array(hex.length / 2);
|
|
26520
|
-
for (let i = 0; i < hex.length; i += 2) {
|
|
26521
|
-
bytes[i / 2] = parseInt(hex.substr(i, 2), 16);
|
|
26522
|
-
}
|
|
26523
|
-
return bytes;
|
|
26524
|
-
}
|
|
26525
|
-
function bufferToBase64(buffer) {
|
|
26526
|
-
let binary = "";
|
|
26527
|
-
for (let i = 0; i < buffer.byteLength; i++) {
|
|
26528
|
-
binary += String.fromCharCode(buffer[i]);
|
|
26529
|
-
}
|
|
26530
|
-
return btoa(binary);
|
|
26531
|
-
}
|
|
26532
|
-
function base64ToBuffer2(base64) {
|
|
26533
|
-
const binary = atob(base64);
|
|
26534
|
-
const bytes = new Uint8Array(binary.length);
|
|
26535
|
-
for (let i = 0; i < binary.length; i++) {
|
|
26536
|
-
bytes[i] = binary.charCodeAt(i);
|
|
26537
|
-
}
|
|
26538
|
-
return bytes;
|
|
26539
|
-
}
|
|
26540
|
-
async function encryptEnvs(env, encryptionKey) {
|
|
26541
|
-
const plaintext = JSON.stringify(env);
|
|
26542
|
-
return CryptoUtil.encrypt(plaintext, encryptionKey);
|
|
26543
|
-
}
|
|
26544
|
-
async function decryptEnvs(encrypted, encryptionKey) {
|
|
26545
|
-
const plaintext = await CryptoUtil.decrypt(encrypted, encryptionKey);
|
|
26546
|
-
const parsed = JSON.parse(plaintext);
|
|
26547
|
-
if (!parsed || typeof parsed !== "object") {
|
|
26548
|
-
return {};
|
|
26549
|
-
}
|
|
26550
|
-
const result = {};
|
|
26551
|
-
for (const [key, value] of Object.entries(parsed)) {
|
|
26552
|
-
if (value === void 0 || value === null) continue;
|
|
26553
|
-
result[key] = String(value);
|
|
26554
|
-
}
|
|
26555
|
-
return result;
|
|
26556
|
-
}
|
|
26557
|
-
|
|
26558
|
-
// src/packing/resolver.ts
|
|
26559
|
-
var NamespaceResolutionError = class extends Error {
|
|
26560
|
-
constructor(itemType, itemName, namespace, message) {
|
|
26561
|
-
super(message);
|
|
26562
|
-
this.itemType = itemType;
|
|
26563
|
-
this.itemName = itemName;
|
|
26564
|
-
this.namespace = namespace;
|
|
26565
|
-
this.name = "NamespaceResolutionError";
|
|
26566
|
-
}
|
|
26567
|
-
};
|
|
26568
|
-
function parseQualifiedName(name) {
|
|
26569
|
-
if (name.startsWith("@")) {
|
|
26570
|
-
const firstSlash = name.indexOf("/");
|
|
26571
|
-
if (firstSlash === -1) {
|
|
26572
|
-
return [null, name];
|
|
26573
|
-
}
|
|
26574
|
-
const secondSlash = name.indexOf("/", firstSlash + 1);
|
|
26575
|
-
if (secondSlash === -1) {
|
|
26576
|
-
return [null, name];
|
|
26577
|
-
}
|
|
26578
|
-
return [name.substring(0, secondSlash), name.substring(secondSlash + 1)];
|
|
26579
|
-
}
|
|
26580
|
-
const separatorIndex = name.indexOf("/");
|
|
26581
|
-
if (separatorIndex === -1) {
|
|
26582
|
-
return [null, name];
|
|
26583
|
-
}
|
|
26584
|
-
return [name.substring(0, separatorIndex), name.substring(separatorIndex + 1)];
|
|
26585
|
-
}
|
|
26586
|
-
function qualifyName(packageId, shortName) {
|
|
26587
|
-
return `${packageId}/${shortName}`;
|
|
26588
|
-
}
|
|
26589
|
-
function getShortName(name) {
|
|
26590
|
-
const [, shortName] = parseQualifiedName(name);
|
|
26591
|
-
return shortName;
|
|
26592
|
-
}
|
|
26593
|
-
function resolveTool(registry, name, namespace) {
|
|
26594
|
-
const [pkgId, shortName] = parseQualifiedName(name);
|
|
26595
|
-
if (pkgId !== null) {
|
|
26596
|
-
const pkg = registry.packages[pkgId];
|
|
26597
|
-
if (!pkg) {
|
|
26598
|
-
throw new NamespaceResolutionError(
|
|
26599
|
-
"tool",
|
|
26600
|
-
name,
|
|
26601
|
-
namespace,
|
|
26602
|
-
`Package "${pkgId}" not found`
|
|
26603
|
-
);
|
|
26604
|
-
}
|
|
26605
|
-
throw new NamespaceResolutionError(
|
|
26606
|
-
"tool",
|
|
26607
|
-
name,
|
|
26608
|
-
namespace,
|
|
26609
|
-
`Cannot access tool "${shortName}" from package "${pkgId}". Only entry point agents are accessible cross-package.`
|
|
26610
|
-
);
|
|
26611
|
-
}
|
|
26612
|
-
if (namespace.type === "packed") {
|
|
26613
|
-
const pkg = registry.packages[namespace.packageId];
|
|
26614
|
-
if (!pkg) {
|
|
26615
|
-
throw new NamespaceResolutionError(
|
|
26616
|
-
"tool",
|
|
26617
|
-
name,
|
|
26618
|
-
namespace,
|
|
26619
|
-
`Package "${namespace.packageId}" not found`
|
|
26620
|
-
);
|
|
26621
|
-
}
|
|
26622
|
-
const loader2 = pkg.tools[shortName];
|
|
26623
|
-
if (!loader2) {
|
|
26624
|
-
throw new NamespaceResolutionError(
|
|
26625
|
-
"tool",
|
|
26626
|
-
name,
|
|
26627
|
-
namespace,
|
|
26628
|
-
`Tool "${shortName}" not found in package "${namespace.packageId}"`
|
|
26629
|
-
);
|
|
26630
|
-
}
|
|
26631
|
-
return loader2;
|
|
26632
27016
|
}
|
|
26633
|
-
|
|
26634
|
-
|
|
26635
|
-
|
|
26636
|
-
|
|
26637
|
-
|
|
26638
|
-
|
|
26639
|
-
|
|
27017
|
+
};
|
|
27018
|
+
|
|
27019
|
+
// src/durable-objects/agentbuilder-migrations/0013_add_thread_activity.ts
|
|
27020
|
+
var migration49 = {
|
|
27021
|
+
version: 13,
|
|
27022
|
+
async up(sql) {
|
|
27023
|
+
sql.exec(`ALTER TABLE threads ADD COLUMN last_activity_at INTEGER`);
|
|
27024
|
+
sql.exec(`ALTER TABLE threads ADD COLUMN executing_since INTEGER`);
|
|
27025
|
+
sql.exec(
|
|
27026
|
+
`CREATE INDEX IF NOT EXISTS idx_threads_last_activity_at ON threads(last_activity_at)`
|
|
26640
27027
|
);
|
|
27028
|
+
sql.exec(`UPDATE threads SET last_activity_at = created_at`);
|
|
27029
|
+
sql.exec(`
|
|
27030
|
+
INSERT OR REPLACE INTO _metadata (key, value) VALUES ('schema_version', '13')
|
|
27031
|
+
`);
|
|
26641
27032
|
}
|
|
26642
|
-
|
|
26643
|
-
|
|
26644
|
-
|
|
26645
|
-
|
|
26646
|
-
|
|
26647
|
-
|
|
26648
|
-
|
|
26649
|
-
|
|
26650
|
-
|
|
26651
|
-
|
|
27033
|
+
};
|
|
27034
|
+
|
|
27035
|
+
// src/durable-objects/agentbuilder-migrations/0014_thread_activity_scale.ts
|
|
27036
|
+
var migration50 = {
|
|
27037
|
+
version: 14,
|
|
27038
|
+
async up(sql) {
|
|
27039
|
+
sql.exec(`ALTER TABLE threads ADD COLUMN last_message_preview TEXT`);
|
|
27040
|
+
sql.exec(
|
|
27041
|
+
`CREATE INDEX IF NOT EXISTS idx_threads_executing_since
|
|
27042
|
+
ON threads(executing_since) WHERE executing_since IS NOT NULL`
|
|
26652
27043
|
);
|
|
26653
|
-
|
|
26654
|
-
|
|
26655
|
-
const pkg = registry.packages[namespace.packageId];
|
|
26656
|
-
if (!pkg) {
|
|
26657
|
-
throw new NamespaceResolutionError(
|
|
26658
|
-
"prompt",
|
|
26659
|
-
name,
|
|
26660
|
-
namespace,
|
|
26661
|
-
`Package "${namespace.packageId}" not found`
|
|
26662
|
-
);
|
|
26663
|
-
}
|
|
26664
|
-
const loader2 = pkg.prompts[shortName];
|
|
26665
|
-
if (!loader2) {
|
|
26666
|
-
throw new NamespaceResolutionError(
|
|
26667
|
-
"prompt",
|
|
26668
|
-
name,
|
|
26669
|
-
namespace,
|
|
26670
|
-
`Prompt "${shortName}" not found in package "${namespace.packageId}"`
|
|
26671
|
-
);
|
|
26672
|
-
}
|
|
26673
|
-
return loader2;
|
|
26674
|
-
}
|
|
26675
|
-
const loader = registry.global.prompts[shortName];
|
|
26676
|
-
if (!loader) {
|
|
26677
|
-
throw new NamespaceResolutionError(
|
|
26678
|
-
"prompt",
|
|
26679
|
-
name,
|
|
26680
|
-
namespace,
|
|
26681
|
-
`Prompt "${shortName}" not found in global namespace`
|
|
27044
|
+
sql.exec(
|
|
27045
|
+
`UPDATE threads SET last_activity_at = created_at WHERE last_activity_at IS NULL`
|
|
26682
27046
|
);
|
|
27047
|
+
sql.exec(`
|
|
27048
|
+
INSERT OR REPLACE INTO _metadata (key, value) VALUES ('schema_version', '14')
|
|
27049
|
+
`);
|
|
26683
27050
|
}
|
|
26684
|
-
|
|
26685
|
-
|
|
26686
|
-
|
|
26687
|
-
|
|
26688
|
-
|
|
26689
|
-
|
|
26690
|
-
|
|
26691
|
-
|
|
26692
|
-
|
|
26693
|
-
`Cannot use qualified model name "${name}". Models must be unqualified. If this is a provider model name, ensure no package named "${possiblePkgId}" exists.`
|
|
27051
|
+
};
|
|
27052
|
+
|
|
27053
|
+
// src/durable-objects/agentbuilder-migrations/0015_clear_envelope_previews.ts
|
|
27054
|
+
var migration51 = {
|
|
27055
|
+
version: 15,
|
|
27056
|
+
async up(sql) {
|
|
27057
|
+
sql.exec(
|
|
27058
|
+
`UPDATE threads SET last_message_preview = NULL
|
|
27059
|
+
WHERE last_message_preview LIKE 'Subagent (reference: %'`
|
|
26694
27060
|
);
|
|
27061
|
+
sql.exec(`
|
|
27062
|
+
INSERT OR REPLACE INTO _metadata (key, value) VALUES ('schema_version', '15')
|
|
27063
|
+
`);
|
|
26695
27064
|
}
|
|
26696
|
-
|
|
26697
|
-
|
|
26698
|
-
|
|
26699
|
-
|
|
26700
|
-
|
|
26701
|
-
|
|
26702
|
-
|
|
26703
|
-
|
|
26704
|
-
|
|
26705
|
-
const globalLoader = registry.global.models[lookupName];
|
|
26706
|
-
if (globalLoader) {
|
|
26707
|
-
return globalLoader;
|
|
26708
|
-
}
|
|
26709
|
-
throw new NamespaceResolutionError(
|
|
26710
|
-
"model",
|
|
26711
|
-
name,
|
|
26712
|
-
namespace,
|
|
26713
|
-
`Model "${lookupName}" not found in package "${namespace.packageId}" or global namespace`
|
|
27065
|
+
};
|
|
27066
|
+
|
|
27067
|
+
// src/durable-objects/agentbuilder-migrations/0016_add_origin_agent.ts
|
|
27068
|
+
var migration52 = {
|
|
27069
|
+
version: 16,
|
|
27070
|
+
async up(sql) {
|
|
27071
|
+
sql.exec(`ALTER TABLE threads ADD COLUMN origin_agent_name TEXT`);
|
|
27072
|
+
sql.exec(
|
|
27073
|
+
`CREATE INDEX IF NOT EXISTS idx_threads_origin_agent_name ON threads(origin_agent_name)`
|
|
26714
27074
|
);
|
|
27075
|
+
sql.exec(`UPDATE threads SET origin_agent_name = agent_name`);
|
|
27076
|
+
sql.exec(`
|
|
27077
|
+
INSERT OR REPLACE INTO _metadata (key, value) VALUES ('schema_version', '16')
|
|
27078
|
+
`);
|
|
26715
27079
|
}
|
|
26716
|
-
|
|
26717
|
-
|
|
26718
|
-
|
|
26719
|
-
|
|
26720
|
-
|
|
26721
|
-
|
|
26722
|
-
|
|
26723
|
-
);
|
|
27080
|
+
};
|
|
27081
|
+
|
|
27082
|
+
// src/durable-objects/agentbuilder-migrations/0017_add_thread_message_recency.ts
|
|
27083
|
+
var migration53 = {
|
|
27084
|
+
version: 17,
|
|
27085
|
+
async up(sql) {
|
|
27086
|
+
sql.exec(`ALTER TABLE threads ADD COLUMN last_message_at INTEGER`);
|
|
27087
|
+
sql.exec(`UPDATE threads SET last_message_at = created_at`);
|
|
27088
|
+
sql.exec(`
|
|
27089
|
+
INSERT OR REPLACE INTO _metadata (key, value) VALUES ('schema_version', '17')
|
|
27090
|
+
`);
|
|
26724
27091
|
}
|
|
26725
|
-
|
|
26726
|
-
|
|
26727
|
-
|
|
26728
|
-
|
|
26729
|
-
|
|
26730
|
-
|
|
26731
|
-
|
|
26732
|
-
|
|
26733
|
-
|
|
26734
|
-
|
|
26735
|
-
|
|
26736
|
-
|
|
26737
|
-
|
|
26738
|
-
|
|
26739
|
-
|
|
26740
|
-
|
|
26741
|
-
|
|
26742
|
-
|
|
26743
|
-
|
|
26744
|
-
|
|
26745
|
-
|
|
26746
|
-
|
|
26747
|
-
|
|
26748
|
-
|
|
26749
|
-
|
|
26750
|
-
|
|
26751
|
-
|
|
26752
|
-
|
|
26753
|
-
|
|
26754
|
-
)
|
|
26755
|
-
|
|
26756
|
-
return loader;
|
|
27092
|
+
};
|
|
27093
|
+
|
|
27094
|
+
// src/durable-objects/agentbuilder-migrations/0018_auth_security.ts
|
|
27095
|
+
var migration54 = {
|
|
27096
|
+
version: 18,
|
|
27097
|
+
async up(sql) {
|
|
27098
|
+
sql.exec(`
|
|
27099
|
+
CREATE TABLE IF NOT EXISTS super_admin_sessions (
|
|
27100
|
+
token_hash TEXT PRIMARY KEY,
|
|
27101
|
+
created_at INTEGER NOT NULL,
|
|
27102
|
+
expires_at INTEGER NOT NULL
|
|
27103
|
+
)
|
|
27104
|
+
`);
|
|
27105
|
+
sql.exec(`
|
|
27106
|
+
CREATE INDEX IF NOT EXISTS idx_super_admin_sessions_expires
|
|
27107
|
+
ON super_admin_sessions(expires_at)
|
|
27108
|
+
`);
|
|
27109
|
+
sql.exec(`
|
|
27110
|
+
CREATE TABLE IF NOT EXISTS auth_rate_limits (
|
|
27111
|
+
bucket_key TEXT PRIMARY KEY,
|
|
27112
|
+
attempts INTEGER NOT NULL,
|
|
27113
|
+
reset_at INTEGER NOT NULL
|
|
27114
|
+
)
|
|
27115
|
+
`);
|
|
27116
|
+
sql.exec(`
|
|
27117
|
+
CREATE INDEX IF NOT EXISTS idx_auth_rate_limits_reset
|
|
27118
|
+
ON auth_rate_limits(reset_at)
|
|
27119
|
+
`);
|
|
27120
|
+
sql.exec(`
|
|
27121
|
+
INSERT OR REPLACE INTO _metadata (key, value) VALUES ('schema_version', '18')
|
|
27122
|
+
`);
|
|
26757
27123
|
}
|
|
26758
|
-
|
|
26759
|
-
|
|
26760
|
-
|
|
26761
|
-
|
|
26762
|
-
|
|
26763
|
-
|
|
26764
|
-
|
|
26765
|
-
|
|
26766
|
-
|
|
26767
|
-
|
|
26768
|
-
|
|
26769
|
-
|
|
26770
|
-
|
|
26771
|
-
|
|
26772
|
-
|
|
26773
|
-
|
|
26774
|
-
|
|
26775
|
-
)
|
|
26776
|
-
|
|
26777
|
-
|
|
27124
|
+
};
|
|
27125
|
+
|
|
27126
|
+
// src/durable-objects/agentbuilder-migrations/0019_scope_skills.ts
|
|
27127
|
+
var migration55 = {
|
|
27128
|
+
version: 19,
|
|
27129
|
+
async up(sql) {
|
|
27130
|
+
sql.exec(`
|
|
27131
|
+
CREATE TABLE skills_0019 (
|
|
27132
|
+
owner_id TEXT NOT NULL,
|
|
27133
|
+
name TEXT NOT NULL,
|
|
27134
|
+
description TEXT NOT NULL,
|
|
27135
|
+
version TEXT,
|
|
27136
|
+
enabled INTEGER NOT NULL DEFAULT 1,
|
|
27137
|
+
shared INTEGER NOT NULL DEFAULT 0,
|
|
27138
|
+
created_at INTEGER DEFAULT (strftime('%s', 'now')),
|
|
27139
|
+
updated_at INTEGER DEFAULT (strftime('%s', 'now')),
|
|
27140
|
+
PRIMARY KEY (owner_id, name)
|
|
27141
|
+
)
|
|
27142
|
+
`);
|
|
27143
|
+
sql.exec(`
|
|
27144
|
+
INSERT INTO skills_0019 (
|
|
27145
|
+
owner_id, name, description, version, enabled, shared, created_at, updated_at
|
|
27146
|
+
)
|
|
27147
|
+
SELECT '__instance_shared__', name, description, version, enabled, 1, created_at, updated_at
|
|
27148
|
+
FROM skills
|
|
27149
|
+
`);
|
|
27150
|
+
sql.exec(`
|
|
27151
|
+
CREATE TABLE skill_files_0019 (
|
|
27152
|
+
owner_id TEXT NOT NULL,
|
|
27153
|
+
skill_name TEXT NOT NULL,
|
|
27154
|
+
path TEXT NOT NULL,
|
|
27155
|
+
content TEXT NOT NULL,
|
|
27156
|
+
size INTEGER NOT NULL,
|
|
27157
|
+
PRIMARY KEY (owner_id, skill_name, path),
|
|
27158
|
+
FOREIGN KEY (owner_id, skill_name) REFERENCES skills_0019(owner_id, name) ON DELETE CASCADE
|
|
27159
|
+
)
|
|
27160
|
+
`);
|
|
27161
|
+
sql.exec(`
|
|
27162
|
+
INSERT INTO skill_files_0019 (owner_id, skill_name, path, content, size)
|
|
27163
|
+
SELECT '__instance_shared__', skill_name, path, content, size FROM skill_files
|
|
27164
|
+
`);
|
|
27165
|
+
sql.exec(`DROP TABLE skill_files`);
|
|
27166
|
+
sql.exec(`DROP TABLE skills`);
|
|
27167
|
+
sql.exec(`ALTER TABLE skills_0019 RENAME TO skills`);
|
|
27168
|
+
sql.exec(`ALTER TABLE skill_files_0019 RENAME TO skill_files`);
|
|
27169
|
+
sql.exec(`CREATE INDEX idx_skills_owner_enabled ON skills(owner_id, enabled)`);
|
|
27170
|
+
sql.exec(`CREATE INDEX idx_skills_shared_enabled ON skills(shared, enabled)`);
|
|
27171
|
+
sql.exec(`CREATE INDEX idx_skill_files_skill ON skill_files(owner_id, skill_name)`);
|
|
27172
|
+
sql.exec(`INSERT OR REPLACE INTO _metadata (key, value) VALUES ('schema_version', '19')`);
|
|
26778
27173
|
}
|
|
26779
|
-
|
|
26780
|
-
|
|
26781
|
-
|
|
27174
|
+
};
|
|
27175
|
+
|
|
27176
|
+
// src/durable-objects/agentbuilder-migrations/0020_websocket_tickets.ts
|
|
27177
|
+
var migration56 = {
|
|
27178
|
+
version: 20,
|
|
27179
|
+
async up(sql) {
|
|
27180
|
+
sql.exec(`
|
|
27181
|
+
CREATE TABLE websocket_tickets (
|
|
27182
|
+
ticket_hash TEXT PRIMARY KEY,
|
|
27183
|
+
pathname TEXT NOT NULL,
|
|
27184
|
+
auth_json TEXT NOT NULL,
|
|
27185
|
+
created_at INTEGER NOT NULL,
|
|
27186
|
+
expires_at INTEGER NOT NULL
|
|
27187
|
+
)
|
|
27188
|
+
`);
|
|
27189
|
+
sql.exec(`
|
|
27190
|
+
CREATE INDEX idx_websocket_tickets_expires
|
|
27191
|
+
ON websocket_tickets(expires_at)
|
|
27192
|
+
`);
|
|
27193
|
+
sql.exec(`INSERT OR REPLACE INTO _metadata (key, value) VALUES ('schema_version', '20')`);
|
|
26782
27194
|
}
|
|
26783
|
-
|
|
26784
|
-
|
|
26785
|
-
|
|
26786
|
-
|
|
26787
|
-
|
|
26788
|
-
|
|
26789
|
-
|
|
27195
|
+
};
|
|
27196
|
+
|
|
27197
|
+
// src/durable-objects/agentbuilder-migrations/0021_platform_handoff_jtis.ts
|
|
27198
|
+
var migration57 = {
|
|
27199
|
+
version: 21,
|
|
27200
|
+
async up(sql) {
|
|
27201
|
+
sql.exec(`
|
|
27202
|
+
CREATE TABLE platform_handoff_jtis (
|
|
27203
|
+
jti TEXT PRIMARY KEY,
|
|
27204
|
+
consumed_at INTEGER NOT NULL,
|
|
27205
|
+
expires_at INTEGER NOT NULL
|
|
27206
|
+
)
|
|
27207
|
+
`);
|
|
27208
|
+
sql.exec(`
|
|
27209
|
+
CREATE INDEX idx_platform_handoff_jtis_expires
|
|
27210
|
+
ON platform_handoff_jtis(expires_at)
|
|
27211
|
+
`);
|
|
27212
|
+
sql.exec(`INSERT OR REPLACE INTO _metadata (key, value) VALUES ('schema_version', '21')`);
|
|
26790
27213
|
}
|
|
26791
|
-
|
|
26792
|
-
|
|
26793
|
-
|
|
26794
|
-
|
|
26795
|
-
|
|
26796
|
-
)
|
|
26797
|
-
|
|
26798
|
-
|
|
26799
|
-
|
|
26800
|
-
|
|
26801
|
-
|
|
26802
|
-
|
|
26803
|
-
|
|
26804
|
-
|
|
26805
|
-
|
|
27214
|
+
};
|
|
27215
|
+
|
|
27216
|
+
// src/durable-objects/agentbuilder-migrations/index.ts
|
|
27217
|
+
var migrations2 = [migration37, migration38, migration39, migration40, migration41, migration42, migration43, migration44, migration45, migration46, migration47, migration48, migration49, migration50, migration51, migration52, migration53, migration54, migration55, migration56, migration57];
|
|
27218
|
+
var LATEST_SCHEMA_VERSION2 = migrations2.reduce(
|
|
27219
|
+
(max, migration58) => Math.max(max, migration58.version),
|
|
27220
|
+
0
|
|
27221
|
+
);
|
|
27222
|
+
|
|
27223
|
+
// src/utils/crypto.ts
|
|
27224
|
+
var CryptoUtil = class {
|
|
27225
|
+
static algorithm = "aes-256-gcm";
|
|
27226
|
+
/**
|
|
27227
|
+
* Encrypt a string value
|
|
27228
|
+
*/
|
|
27229
|
+
static async encrypt(text, key) {
|
|
27230
|
+
const encoder = new TextEncoder();
|
|
27231
|
+
const data = encoder.encode(text);
|
|
27232
|
+
const cryptoKey = await crypto.subtle.importKey(
|
|
27233
|
+
"raw",
|
|
27234
|
+
hexToBuffer(key),
|
|
27235
|
+
{ name: "AES-GCM" },
|
|
27236
|
+
false,
|
|
27237
|
+
["encrypt"]
|
|
27238
|
+
);
|
|
27239
|
+
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
27240
|
+
const encrypted = await crypto.subtle.encrypt(
|
|
27241
|
+
{
|
|
27242
|
+
name: "AES-GCM",
|
|
27243
|
+
iv
|
|
27244
|
+
},
|
|
27245
|
+
cryptoKey,
|
|
27246
|
+
data
|
|
26806
27247
|
);
|
|
27248
|
+
const combined = new Uint8Array(iv.length + encrypted.byteLength);
|
|
27249
|
+
combined.set(iv);
|
|
27250
|
+
combined.set(new Uint8Array(encrypted), iv.length);
|
|
27251
|
+
return bufferToBase64(combined);
|
|
26807
27252
|
}
|
|
26808
|
-
|
|
26809
|
-
|
|
26810
|
-
|
|
26811
|
-
|
|
26812
|
-
|
|
26813
|
-
|
|
26814
|
-
|
|
26815
|
-
|
|
26816
|
-
|
|
27253
|
+
/**
|
|
27254
|
+
* Decrypt a string value
|
|
27255
|
+
*/
|
|
27256
|
+
static async decrypt(encryptedText, key) {
|
|
27257
|
+
const combined = base64ToBuffer2(encryptedText);
|
|
27258
|
+
const iv = combined.slice(0, 12);
|
|
27259
|
+
const encrypted = combined.slice(12);
|
|
27260
|
+
const cryptoKey = await crypto.subtle.importKey(
|
|
27261
|
+
"raw",
|
|
27262
|
+
hexToBuffer(key),
|
|
27263
|
+
{ name: "AES-GCM" },
|
|
27264
|
+
false,
|
|
27265
|
+
["decrypt"]
|
|
27266
|
+
);
|
|
27267
|
+
const decrypted = await crypto.subtle.decrypt(
|
|
27268
|
+
{
|
|
27269
|
+
name: "AES-GCM",
|
|
27270
|
+
iv
|
|
27271
|
+
},
|
|
27272
|
+
cryptoKey,
|
|
27273
|
+
encrypted
|
|
27274
|
+
);
|
|
27275
|
+
const decoder = new TextDecoder();
|
|
27276
|
+
return decoder.decode(decrypted);
|
|
26817
27277
|
}
|
|
26818
|
-
|
|
26819
|
-
|
|
26820
|
-
|
|
26821
|
-
|
|
26822
|
-
|
|
26823
|
-
const pkg = registry.packages[namespace.packageId];
|
|
26824
|
-
return pkg ? Object.keys(pkg.tools) : [];
|
|
27278
|
+
};
|
|
27279
|
+
function hexToBuffer(hex) {
|
|
27280
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
27281
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
27282
|
+
bytes[i / 2] = parseInt(hex.substr(i, 2), 16);
|
|
26825
27283
|
}
|
|
26826
|
-
return
|
|
27284
|
+
return bytes;
|
|
26827
27285
|
}
|
|
26828
|
-
function
|
|
26829
|
-
|
|
26830
|
-
|
|
26831
|
-
|
|
26832
|
-
const otherEntryPoints = Object.entries(registry.packages).filter(([id]) => id !== namespace.packageId).flatMap(
|
|
26833
|
-
([pkgId, pkg2]) => pkg2.entryAgents.map((name) => qualifyName(pkgId, name))
|
|
26834
|
-
);
|
|
26835
|
-
return [...ownAgents, ...otherEntryPoints];
|
|
27286
|
+
function bufferToBase64(buffer) {
|
|
27287
|
+
let binary = "";
|
|
27288
|
+
for (let i = 0; i < buffer.byteLength; i++) {
|
|
27289
|
+
binary += String.fromCharCode(buffer[i]);
|
|
26836
27290
|
}
|
|
26837
|
-
|
|
26838
|
-
const entryPoints = Object.values(registry.packages).flatMap((pkg) => pkg.entryAgents);
|
|
26839
|
-
return [.../* @__PURE__ */ new Set([...globalAgents, ...entryPoints])];
|
|
27291
|
+
return btoa(binary);
|
|
26840
27292
|
}
|
|
26841
|
-
function
|
|
26842
|
-
|
|
26843
|
-
|
|
26844
|
-
|
|
27293
|
+
function base64ToBuffer2(base64) {
|
|
27294
|
+
const binary = atob(base64);
|
|
27295
|
+
const bytes = new Uint8Array(binary.length);
|
|
27296
|
+
for (let i = 0; i < binary.length; i++) {
|
|
27297
|
+
bytes[i] = binary.charCodeAt(i);
|
|
26845
27298
|
}
|
|
26846
|
-
return
|
|
27299
|
+
return bytes;
|
|
26847
27300
|
}
|
|
26848
|
-
function
|
|
26849
|
-
|
|
26850
|
-
|
|
26851
|
-
const ownModels = pkg ? Object.keys(pkg.models) : [];
|
|
26852
|
-
const globalModels = Object.keys(registry.global.models);
|
|
26853
|
-
return [.../* @__PURE__ */ new Set([...ownModels, ...globalModels])];
|
|
26854
|
-
}
|
|
26855
|
-
return Object.keys(registry.global.models);
|
|
27301
|
+
async function encryptEnvs(env, encryptionKey) {
|
|
27302
|
+
const plaintext = JSON.stringify(env);
|
|
27303
|
+
return CryptoUtil.encrypt(plaintext, encryptionKey);
|
|
26856
27304
|
}
|
|
26857
|
-
function
|
|
26858
|
-
|
|
26859
|
-
|
|
27305
|
+
async function decryptEnvs(encrypted, encryptionKey) {
|
|
27306
|
+
const plaintext = await CryptoUtil.decrypt(encrypted, encryptionKey);
|
|
27307
|
+
const parsed = JSON.parse(plaintext);
|
|
27308
|
+
if (!parsed || typeof parsed !== "object") {
|
|
27309
|
+
return {};
|
|
26860
27310
|
}
|
|
26861
|
-
|
|
26862
|
-
|
|
26863
|
-
|
|
26864
|
-
|
|
26865
|
-
const firstSlash = name.indexOf("/");
|
|
26866
|
-
if (firstSlash === -1) return false;
|
|
26867
|
-
return name.indexOf("/", firstSlash + 1) !== -1;
|
|
27311
|
+
const result = {};
|
|
27312
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
27313
|
+
if (value === void 0 || value === null) continue;
|
|
27314
|
+
result[key] = String(value);
|
|
26868
27315
|
}
|
|
26869
|
-
return
|
|
27316
|
+
return result;
|
|
26870
27317
|
}
|
|
26871
27318
|
|
|
26872
27319
|
// src/durable-objects/DurableAgentBuilder.ts
|
|
27320
|
+
init_resolver();
|
|
26873
27321
|
init_types();
|
|
26874
27322
|
|
|
26875
27323
|
// src/skills/frontmatter.ts
|
|
@@ -26961,6 +27409,7 @@ function validateSkillFiles(files) {
|
|
|
26961
27409
|
|
|
26962
27410
|
// src/durable-objects/DurableAgentBuilder.ts
|
|
26963
27411
|
init_scope();
|
|
27412
|
+
init_ParentHookResolver();
|
|
26964
27413
|
var ENV_TYPES_PROPERTY = "__agentbuilder_env_types";
|
|
26965
27414
|
function parseStoredPermissions(value) {
|
|
26966
27415
|
if (typeof value !== "string" || !value.trim()) return null;
|
|
@@ -27642,16 +28091,29 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
|
|
|
27642
28091
|
} catch {
|
|
27643
28092
|
return;
|
|
27644
28093
|
}
|
|
27645
|
-
const
|
|
27646
|
-
|
|
27647
|
-
|
|
27648
|
-
|
|
27649
|
-
|
|
27650
|
-
|
|
27651
|
-
|
|
27652
|
-
|
|
27653
|
-
|
|
27654
|
-
|
|
28094
|
+
const packageId = agentDef?.__package?.packageId;
|
|
28095
|
+
const rawPromptName = agentDef?.sideA?.prompt;
|
|
28096
|
+
const promptName = rawPromptName && packageId && !isQualifiedName(rawPromptName) ? `${packageId}/${rawPromptName}` : rawPromptName;
|
|
28097
|
+
const promptDef = promptName ? await this.loadPrompt(promptName) : void 0;
|
|
28098
|
+
const bindings = await resolveHooksForPrompt(
|
|
28099
|
+
{
|
|
28100
|
+
host: this,
|
|
28101
|
+
agentName: thread.agent_name,
|
|
28102
|
+
agent: agentDef,
|
|
28103
|
+
promptName,
|
|
28104
|
+
prompt: promptDef,
|
|
28105
|
+
isOptionalRelationshipEnabled: async (envName) => {
|
|
28106
|
+
const value = await this.resolveThreadEnv({
|
|
28107
|
+
threadId: thread.id,
|
|
28108
|
+
property: envName,
|
|
28109
|
+
promptName: promptName ?? agentDef.name ?? thread.agent_name
|
|
28110
|
+
});
|
|
28111
|
+
return ["true", "1", "yes"].includes((value ?? "").trim().toLowerCase());
|
|
28112
|
+
}
|
|
28113
|
+
},
|
|
28114
|
+
"after_thread_created"
|
|
28115
|
+
);
|
|
28116
|
+
if (bindings.length === 0) return;
|
|
27655
28117
|
const durableId = this.env.AGENT_BUILDER_THREAD.idFromName(thread.id);
|
|
27656
28118
|
const threadStub = this.env.AGENT_BUILDER_THREAD.get(durableId);
|
|
27657
28119
|
const { ThreadStateImpl: ThreadStateImpl2 } = await Promise.resolve().then(() => (init_ThreadStateImpl(), ThreadStateImpl_exports));
|
|
@@ -27666,16 +28128,14 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
|
|
|
27666
28128
|
terminated: thread.terminated,
|
|
27667
28129
|
created_at: thread.created_at
|
|
27668
28130
|
});
|
|
27669
|
-
for (const
|
|
27670
|
-
const hookLoader = hooksRegistry[hookId];
|
|
27671
|
-
if (!hookLoader) continue;
|
|
28131
|
+
for (const binding of bindings) {
|
|
27672
28132
|
try {
|
|
27673
|
-
|
|
27674
|
-
if (hookDef?.hook === "after_thread_created") {
|
|
27675
|
-
await hookDef.execute(threadState);
|
|
27676
|
-
}
|
|
28133
|
+
await binding.execute(threadState, binding.context);
|
|
27677
28134
|
} catch (error) {
|
|
27678
|
-
console.error(
|
|
28135
|
+
console.error(
|
|
28136
|
+
`[Hooks] \u2717 Error running after_thread_created hook '${binding.id}':`,
|
|
28137
|
+
error
|
|
28138
|
+
);
|
|
27679
28139
|
}
|
|
27680
28140
|
}
|
|
27681
28141
|
}
|
|
@@ -28887,6 +29347,15 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
|
|
|
28887
29347
|
* Load a prompt definition by name.
|
|
28888
29348
|
*/
|
|
28889
29349
|
async loadPrompt(name) {
|
|
29350
|
+
if (isQualifiedName(name)) {
|
|
29351
|
+
const [packageId, promptName] = parseQualifiedName(name);
|
|
29352
|
+
const pkg = packageId ? this.registry()?.packages?.[packageId] : void 0;
|
|
29353
|
+
const loader2 = pkg?.prompts?.[promptName];
|
|
29354
|
+
if (!loader2) {
|
|
29355
|
+
throw new Error(`Prompt not found: ${name}`);
|
|
29356
|
+
}
|
|
29357
|
+
return await loader2();
|
|
29358
|
+
}
|
|
28890
29359
|
const registry = this.prompts();
|
|
28891
29360
|
const loader = registry[name];
|
|
28892
29361
|
if (!loader) {
|
|
@@ -30176,6 +30645,7 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
|
|
|
30176
30645
|
init_StreamManager();
|
|
30177
30646
|
init_LLMRequest();
|
|
30178
30647
|
init_ThreadStateImpl();
|
|
30648
|
+
init_resolver();
|
|
30179
30649
|
|
|
30180
30650
|
// src/durable-objects/logDetailStream.ts
|
|
30181
30651
|
var LOG_DETAIL_HEAVY_FIELDS = [
|
|
@@ -30849,6 +31319,7 @@ var DurableThread = class _DurableThread extends DurableObject {
|
|
|
30849
31319
|
type: agentDef.type,
|
|
30850
31320
|
created_at: Date.now(),
|
|
30851
31321
|
max_session_turns: agentDef.maxSessionTurns,
|
|
31322
|
+
_package: agentDef.__package,
|
|
30852
31323
|
side_a_label: agentDef.sideA?.label,
|
|
30853
31324
|
side_a_agent_prompt: qualifyPromptName(agentDef.sideA?.prompt),
|
|
30854
31325
|
side_a_stop_on_response: agentDef.sideA?.stopOnResponse ?? true,
|
|
@@ -36083,6 +36554,8 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
36083
36554
|
type: agentDef.type,
|
|
36084
36555
|
created_at: Date.now(),
|
|
36085
36556
|
max_session_turns: agentDef.maxSessionTurns,
|
|
36557
|
+
hooks: agentDef.hooks ?? [],
|
|
36558
|
+
_package: agentDef.__package,
|
|
36086
36559
|
side_a_label: agentDef.sideA?.label,
|
|
36087
36560
|
side_a_agent_prompt: qualifyPromptName(agentDef.sideA?.prompt),
|
|
36088
36561
|
side_a_stop_on_response: agentDef.sideA?.stopOnResponse ?? true,
|
|
@@ -36308,6 +36781,8 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
36308
36781
|
type: agentDef.type,
|
|
36309
36782
|
created_at: Date.now(),
|
|
36310
36783
|
max_session_turns: agentDef.maxSessionTurns,
|
|
36784
|
+
hooks: agentDef.hooks ?? [],
|
|
36785
|
+
_package: agentDef.__package,
|
|
36311
36786
|
side_a_label: agentDef.sideA?.label,
|
|
36312
36787
|
side_a_agent_prompt: qualifyPromptName(agentDef.sideA?.prompt),
|
|
36313
36788
|
side_a_stop_on_response: agentDef.sideA?.stopOnResponse ?? true,
|
|
@@ -36464,6 +36939,8 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
36464
36939
|
type: agentDef.type,
|
|
36465
36940
|
created_at: Date.now(),
|
|
36466
36941
|
max_session_turns: agentDef.maxSessionTurns,
|
|
36942
|
+
hooks: agentDef.hooks ?? [],
|
|
36943
|
+
_package: agentDef.__package,
|
|
36467
36944
|
side_a_label: agentDef.sideA?.label,
|
|
36468
36945
|
side_a_agent_prompt: qualifyPromptName(agentDef.sideA?.prompt),
|
|
36469
36946
|
side_a_stop_on_response: agentDef.sideA?.stopOnResponse ?? true,
|
|
@@ -38421,6 +38898,9 @@ init_context();
|
|
|
38421
38898
|
init_ProviderRegistry();
|
|
38422
38899
|
init_types2();
|
|
38423
38900
|
|
|
38901
|
+
// src/packing/index.ts
|
|
38902
|
+
init_resolver();
|
|
38903
|
+
|
|
38424
38904
|
export { CLIENT_STREAM_CHUNK_BYTES, CodeExecutionBridge, DurableAgentBuilder, DurableThread, DurableUserHub, FlowStateSdk, NamespaceResolutionError, PackageDiscoveryService, ProviderRegistry, ThreadWatchdog, agentbuilder, applyRuntimeCors, assistantMessageText, authenticate, buildImageDescription, builder, callClient, callClientStream, canAccessThread, cat, createNamespaceContext, createThreadEndpointHandler, decodeStreamChunk, defineController2 as defineController, discoverPackages, emitThreadEvent, encodeStreamChunk, endpointCallerFromAuth, enhanceFlowState, exists, find, forceTurn, generateAgentFile, generateImageDescription, generateModelFile, generatePromptFile, getFileStats, getMessages, getMessagesToSummarize, getShortName, getThumbnail, getUnsummarizedImageAttachments, getVisibleAgentNames, getVisibleModelNames, getVisiblePromptNames, getVisibleToolNames, grep, hasImageAttachments, hasJsonArrayEntries, head, injectMessage, isAdminOnlyApiRoute, isHostedInstance, isPublicApiRoute, isQualifiedName, isSameOriginBrowserRequest, isTrustedLocalDevelopmentRequest, isVisibleTerminalAssistantMessage, linkFile, messageTimestampSeconds, mkdir, move, optimizeImageContext, parseQualifiedName, qualifyName, queueTool, readFile, readdir, reloadHistory, rename, replaceImagesWithDescriptions, requireAdmin, requireAuth, resolveAgent, resolveHook, resolveModel, resolvePrompt, resolveTool, rmdir, runtimeCorsHeaders, runtimePreflightResponse, stat, supportsClientForwarding, tail, unlink, updateThread, writeFile, writeImage };
|
|
38425
38905
|
//# sourceMappingURL=index.js.map
|
|
38426
38906
|
//# sourceMappingURL=index.js.map
|