struere 0.12.5 → 0.12.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin/struere.js
CHANGED
|
@@ -1735,11 +1735,32 @@ function defineTools(tools) {
|
|
|
1735
1735
|
})
|
|
1736
1736
|
}
|
|
1737
1737
|
|
|
1738
|
+
function defineRouter(config) {
|
|
1739
|
+
const VALID_OPERATORS = ['eq', 'neq', 'in', 'contains', 'regex', 'gt', 'lt', 'exists']
|
|
1740
|
+
if (!config.name) throw new Error('Router name is required')
|
|
1741
|
+
if (!config.slug) throw new Error('Router slug is required')
|
|
1742
|
+
if (!config.agents || config.agents.length === 0) throw new Error('Router must have at least one agent')
|
|
1743
|
+
var agentSlugs = new Set(config.agents.map(function(a) { return a.slug }))
|
|
1744
|
+
if (!agentSlugs.has(config.fallback)) throw new Error('Router fallback "' + config.fallback + '" must reference an agent slug in the agents array')
|
|
1745
|
+
if (config.mode === 'rules') {
|
|
1746
|
+
if (!config.rules || config.rules.length === 0) throw new Error('Router with mode "rules" must have at least one rule')
|
|
1747
|
+
for (var rule of config.rules) {
|
|
1748
|
+
if (!rule.conditions || rule.conditions.length === 0) throw new Error('Each router rule must have at least one condition')
|
|
1749
|
+
if (!agentSlugs.has(rule.route)) throw new Error('Router rule route "' + rule.route + '" must reference an agent slug in the agents array')
|
|
1750
|
+
for (var condition of rule.conditions) {
|
|
1751
|
+
if (!condition.field) throw new Error('Router rule condition field is required')
|
|
1752
|
+
if (!VALID_OPERATORS.includes(condition.operator)) throw new Error('Router rule condition operator must be one of: ' + VALID_OPERATORS.join(', '))
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
return config
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1738
1759
|
function defineEntityType() {
|
|
1739
1760
|
throw new Error('defineEntityType has been renamed to defineData. Please update your imports: import { defineData } from "struere"')
|
|
1740
1761
|
}
|
|
1741
1762
|
|
|
1742
|
-
export { defineAgent, defineRole, defineData, defineEntityType, defineTrigger, defineTools }
|
|
1763
|
+
export { defineAgent, defineRole, defineData, defineEntityType, defineTrigger, defineTools, defineRouter }
|
|
1743
1764
|
`;
|
|
1744
1765
|
function registerStruerePlugin() {
|
|
1745
1766
|
if (registered)
|
|
@@ -1956,12 +1977,43 @@ export interface TriggerConfig {
|
|
|
1956
1977
|
}
|
|
1957
1978
|
}
|
|
1958
1979
|
|
|
1980
|
+
export interface RouterAgentRef {
|
|
1981
|
+
slug: string
|
|
1982
|
+
description: string
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1985
|
+
export interface RouterRuleCondition {
|
|
1986
|
+
field: string
|
|
1987
|
+
operator: 'eq' | 'neq' | 'in' | 'contains' | 'regex' | 'gt' | 'lt' | 'exists'
|
|
1988
|
+
value?: unknown
|
|
1989
|
+
}
|
|
1990
|
+
|
|
1991
|
+
export interface RouterRule {
|
|
1992
|
+
conditions: RouterRuleCondition[]
|
|
1993
|
+
route: string
|
|
1994
|
+
}
|
|
1995
|
+
|
|
1996
|
+
export interface RouterConfig {
|
|
1997
|
+
name: string
|
|
1998
|
+
slug: string
|
|
1999
|
+
description?: string
|
|
2000
|
+
mode: 'rules' | 'classify'
|
|
2001
|
+
agents: RouterAgentRef[]
|
|
2002
|
+
rules?: RouterRule[]
|
|
2003
|
+
fallback: string
|
|
2004
|
+
classifyModel?: { model: string; temperature?: number; maxTokens?: number }
|
|
2005
|
+
contextMessages?: number
|
|
2006
|
+
maxTransfers?: number
|
|
2007
|
+
inactivityResetMs?: number
|
|
2008
|
+
}
|
|
2009
|
+
|
|
1959
2010
|
export function defineAgent(config: AgentConfig): AgentConfig
|
|
1960
2011
|
export function defineRole(config: RoleConfig): RoleConfig
|
|
1961
2012
|
export function defineData(config: EntityTypeConfig): EntityTypeConfig
|
|
1962
2013
|
export function defineEntityType(config: EntityTypeConfig): never
|
|
1963
2014
|
export function defineTrigger(config: TriggerConfig): TriggerConfig
|
|
1964
2015
|
export function defineTools(tools: ToolDefinition[]): ToolReference[]
|
|
2016
|
+
export function defineRouter(config: RouterConfig): RouterConfig
|
|
1965
2017
|
`;
|
|
1966
2018
|
function generateTypeDeclarations(cwd) {
|
|
1967
2019
|
const struereDir = join4(cwd, ".struere");
|
|
@@ -2991,6 +3043,7 @@ ${resources.errors.join(`
|
|
|
2991
3043
|
if (environment === "eval") {
|
|
2992
3044
|
const result = await syncOrganization({
|
|
2993
3045
|
agents: payload.agents,
|
|
3046
|
+
tools: payload.tools,
|
|
2994
3047
|
entityTypes: payload.entityTypes,
|
|
2995
3048
|
roles: payload.roles,
|
|
2996
3049
|
evalSuites: payload.evalSuites,
|
|
@@ -3071,7 +3124,7 @@ var syncCommand = new Command5("sync").description("Sync resources to Convex and
|
|
|
3071
3124
|
process.exit(1);
|
|
3072
3125
|
}
|
|
3073
3126
|
if (!jsonMode && !options.dryRun)
|
|
3074
|
-
output.succeed(`Loaded ${resources.agents.length} agents, ${resources.entityTypes.length} data types, ${resources.roles.length} roles`);
|
|
3127
|
+
output.succeed(`Loaded ${resources.agents.length} agents, ${resources.entityTypes.length} data types, ${resources.roles.length} roles, ${resources.customTools.length} custom tools`);
|
|
3075
3128
|
} catch (error) {
|
|
3076
3129
|
if (jsonMode) {
|
|
3077
3130
|
console.log(JSON.stringify({ success: false, error: error instanceof Error ? error.message : String(error) }));
|
|
@@ -3699,6 +3752,7 @@ var deployCommand = new Command7("deploy").description("Deploy all resources to
|
|
|
3699
3752
|
entityTypes: payload.entityTypes,
|
|
3700
3753
|
roles: payload.roles,
|
|
3701
3754
|
triggers: payload.triggers,
|
|
3755
|
+
tools: payload.tools,
|
|
3702
3756
|
organizationId: project.organization.id,
|
|
3703
3757
|
environment: "production"
|
|
3704
3758
|
});
|
|
@@ -7917,7 +7971,7 @@ import { Command as Command19 } from "commander";
|
|
|
7917
7971
|
import chalk21 from "chalk";
|
|
7918
7972
|
import ora15 from "ora";
|
|
7919
7973
|
init_convex();
|
|
7920
|
-
var compilePromptCommand = new Command19("compile-prompt").description("Compile and preview an agent's system prompt after template processing").argument("<agent-slug>", "Agent slug to compile prompt for").option("--env <env>", "Environment: development | production", "development").option("--message <msg>", "Sample message for template context").option("--channel <channel>", "Sample channel (whatsapp, widget, api, dashboard)").option("--param <key=value...>", "Custom thread param (repeatable)", (val, acc) => {
|
|
7974
|
+
var compilePromptCommand = new Command19("compile-prompt").description("Compile and preview an agent's system prompt after template processing").argument("<agent-slug>", "Agent slug to compile prompt for").option("--env <env>", "Environment: development | production | eval", "development").option("--message <msg>", "Sample message for template context").option("--channel <channel>", "Sample channel (whatsapp, widget, api, dashboard)").option("--param <key=value...>", "Custom thread param (repeatable)", (val, acc) => {
|
|
7921
7975
|
acc.push(val);
|
|
7922
7976
|
return acc;
|
|
7923
7977
|
}, []).option("--json", "Output full JSON (raw + compiled + context)").option("--raw", "Show raw uncompiled template instead of compiled").action(async (agentSlug, options) => {
|
|
@@ -8709,7 +8763,7 @@ whatsappCommand.command("set-agent <connection> <agent-slug>").description("Assi
|
|
|
8709
8763
|
// package.json
|
|
8710
8764
|
var package_default = {
|
|
8711
8765
|
name: "struere",
|
|
8712
|
-
version: "0.12.
|
|
8766
|
+
version: "0.12.7",
|
|
8713
8767
|
description: "Build, test, and deploy AI agents",
|
|
8714
8768
|
keywords: [
|
|
8715
8769
|
"ai",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAcnC,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAcnC,eAAO,MAAM,aAAa,SAuUtB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAKnC,OAAO,EAAkC,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAA;AACnG,OAAO,EAAoB,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAMxE,KAAK,WAAW,GAAG,WAAW,CAAC,aAAa,CAAC,CAAA;AAE7C,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,EAAE,CAAA;CAClB;AAED,wBAAsB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CA0C7F;AAED,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,eAAe,EAC1B,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,WAAW,EAAE,WAAW,GACvB,OAAO,CAAC,eAAe,EAAE,CAAC,CAsC5B;
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAKnC,OAAO,EAAkC,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAA;AACnG,OAAO,EAAoB,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAMxE,KAAK,WAAW,GAAG,WAAW,CAAC,aAAa,CAAC,CAAA;AAE7C,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,EAAE,CAAA;CAClB;AAED,wBAAsB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CA0C7F;AAED,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,eAAe,EAC1B,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,WAAW,EAAE,WAAW,GACvB,OAAO,CAAC,eAAe,EAAE,CAAC,CAsC5B;AAyCD,eAAO,MAAM,WAAW,SA2MpB,CAAA"}
|
package/dist/cli/index.js
CHANGED
|
@@ -1735,11 +1735,32 @@ function defineTools(tools) {
|
|
|
1735
1735
|
})
|
|
1736
1736
|
}
|
|
1737
1737
|
|
|
1738
|
+
function defineRouter(config) {
|
|
1739
|
+
const VALID_OPERATORS = ['eq', 'neq', 'in', 'contains', 'regex', 'gt', 'lt', 'exists']
|
|
1740
|
+
if (!config.name) throw new Error('Router name is required')
|
|
1741
|
+
if (!config.slug) throw new Error('Router slug is required')
|
|
1742
|
+
if (!config.agents || config.agents.length === 0) throw new Error('Router must have at least one agent')
|
|
1743
|
+
var agentSlugs = new Set(config.agents.map(function(a) { return a.slug }))
|
|
1744
|
+
if (!agentSlugs.has(config.fallback)) throw new Error('Router fallback "' + config.fallback + '" must reference an agent slug in the agents array')
|
|
1745
|
+
if (config.mode === 'rules') {
|
|
1746
|
+
if (!config.rules || config.rules.length === 0) throw new Error('Router with mode "rules" must have at least one rule')
|
|
1747
|
+
for (var rule of config.rules) {
|
|
1748
|
+
if (!rule.conditions || rule.conditions.length === 0) throw new Error('Each router rule must have at least one condition')
|
|
1749
|
+
if (!agentSlugs.has(rule.route)) throw new Error('Router rule route "' + rule.route + '" must reference an agent slug in the agents array')
|
|
1750
|
+
for (var condition of rule.conditions) {
|
|
1751
|
+
if (!condition.field) throw new Error('Router rule condition field is required')
|
|
1752
|
+
if (!VALID_OPERATORS.includes(condition.operator)) throw new Error('Router rule condition operator must be one of: ' + VALID_OPERATORS.join(', '))
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
return config
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1738
1759
|
function defineEntityType() {
|
|
1739
1760
|
throw new Error('defineEntityType has been renamed to defineData. Please update your imports: import { defineData } from "struere"')
|
|
1740
1761
|
}
|
|
1741
1762
|
|
|
1742
|
-
export { defineAgent, defineRole, defineData, defineEntityType, defineTrigger, defineTools }
|
|
1763
|
+
export { defineAgent, defineRole, defineData, defineEntityType, defineTrigger, defineTools, defineRouter }
|
|
1743
1764
|
`;
|
|
1744
1765
|
function registerStruerePlugin() {
|
|
1745
1766
|
if (registered)
|
|
@@ -1956,12 +1977,43 @@ export interface TriggerConfig {
|
|
|
1956
1977
|
}
|
|
1957
1978
|
}
|
|
1958
1979
|
|
|
1980
|
+
export interface RouterAgentRef {
|
|
1981
|
+
slug: string
|
|
1982
|
+
description: string
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1985
|
+
export interface RouterRuleCondition {
|
|
1986
|
+
field: string
|
|
1987
|
+
operator: 'eq' | 'neq' | 'in' | 'contains' | 'regex' | 'gt' | 'lt' | 'exists'
|
|
1988
|
+
value?: unknown
|
|
1989
|
+
}
|
|
1990
|
+
|
|
1991
|
+
export interface RouterRule {
|
|
1992
|
+
conditions: RouterRuleCondition[]
|
|
1993
|
+
route: string
|
|
1994
|
+
}
|
|
1995
|
+
|
|
1996
|
+
export interface RouterConfig {
|
|
1997
|
+
name: string
|
|
1998
|
+
slug: string
|
|
1999
|
+
description?: string
|
|
2000
|
+
mode: 'rules' | 'classify'
|
|
2001
|
+
agents: RouterAgentRef[]
|
|
2002
|
+
rules?: RouterRule[]
|
|
2003
|
+
fallback: string
|
|
2004
|
+
classifyModel?: { model: string; temperature?: number; maxTokens?: number }
|
|
2005
|
+
contextMessages?: number
|
|
2006
|
+
maxTransfers?: number
|
|
2007
|
+
inactivityResetMs?: number
|
|
2008
|
+
}
|
|
2009
|
+
|
|
1959
2010
|
export function defineAgent(config: AgentConfig): AgentConfig
|
|
1960
2011
|
export function defineRole(config: RoleConfig): RoleConfig
|
|
1961
2012
|
export function defineData(config: EntityTypeConfig): EntityTypeConfig
|
|
1962
2013
|
export function defineEntityType(config: EntityTypeConfig): never
|
|
1963
2014
|
export function defineTrigger(config: TriggerConfig): TriggerConfig
|
|
1964
2015
|
export function defineTools(tools: ToolDefinition[]): ToolReference[]
|
|
2016
|
+
export function defineRouter(config: RouterConfig): RouterConfig
|
|
1965
2017
|
`;
|
|
1966
2018
|
function generateTypeDeclarations(cwd) {
|
|
1967
2019
|
const struereDir = join4(cwd, ".struere");
|
|
@@ -2991,6 +3043,7 @@ ${resources.errors.join(`
|
|
|
2991
3043
|
if (environment === "eval") {
|
|
2992
3044
|
const result = await syncOrganization({
|
|
2993
3045
|
agents: payload.agents,
|
|
3046
|
+
tools: payload.tools,
|
|
2994
3047
|
entityTypes: payload.entityTypes,
|
|
2995
3048
|
roles: payload.roles,
|
|
2996
3049
|
evalSuites: payload.evalSuites,
|
|
@@ -3071,7 +3124,7 @@ var syncCommand = new Command5("sync").description("Sync resources to Convex and
|
|
|
3071
3124
|
process.exit(1);
|
|
3072
3125
|
}
|
|
3073
3126
|
if (!jsonMode && !options.dryRun)
|
|
3074
|
-
output.succeed(`Loaded ${resources.agents.length} agents, ${resources.entityTypes.length} data types, ${resources.roles.length} roles`);
|
|
3127
|
+
output.succeed(`Loaded ${resources.agents.length} agents, ${resources.entityTypes.length} data types, ${resources.roles.length} roles, ${resources.customTools.length} custom tools`);
|
|
3075
3128
|
} catch (error) {
|
|
3076
3129
|
if (jsonMode) {
|
|
3077
3130
|
console.log(JSON.stringify({ success: false, error: error instanceof Error ? error.message : String(error) }));
|
|
@@ -3699,6 +3752,7 @@ var deployCommand = new Command7("deploy").description("Deploy all resources to
|
|
|
3699
3752
|
entityTypes: payload.entityTypes,
|
|
3700
3753
|
roles: payload.roles,
|
|
3701
3754
|
triggers: payload.triggers,
|
|
3755
|
+
tools: payload.tools,
|
|
3702
3756
|
organizationId: project.organization.id,
|
|
3703
3757
|
environment: "production"
|
|
3704
3758
|
});
|
|
@@ -7917,7 +7971,7 @@ import { Command as Command19 } from "commander";
|
|
|
7917
7971
|
import chalk21 from "chalk";
|
|
7918
7972
|
import ora15 from "ora";
|
|
7919
7973
|
init_convex();
|
|
7920
|
-
var compilePromptCommand = new Command19("compile-prompt").description("Compile and preview an agent's system prompt after template processing").argument("<agent-slug>", "Agent slug to compile prompt for").option("--env <env>", "Environment: development | production", "development").option("--message <msg>", "Sample message for template context").option("--channel <channel>", "Sample channel (whatsapp, widget, api, dashboard)").option("--param <key=value...>", "Custom thread param (repeatable)", (val, acc) => {
|
|
7974
|
+
var compilePromptCommand = new Command19("compile-prompt").description("Compile and preview an agent's system prompt after template processing").argument("<agent-slug>", "Agent slug to compile prompt for").option("--env <env>", "Environment: development | production | eval", "development").option("--message <msg>", "Sample message for template context").option("--channel <channel>", "Sample channel (whatsapp, widget, api, dashboard)").option("--param <key=value...>", "Custom thread param (repeatable)", (val, acc) => {
|
|
7921
7975
|
acc.push(val);
|
|
7922
7976
|
return acc;
|
|
7923
7977
|
}, []).option("--json", "Output full JSON (raw + compiled + context)").option("--raw", "Show raw uncompiled template instead of compiled").action(async (agentSlug, options) => {
|
|
@@ -8709,7 +8763,7 @@ whatsappCommand.command("set-agent <connection> <agent-slug>").description("Assi
|
|
|
8709
8763
|
// package.json
|
|
8710
8764
|
var package_default = {
|
|
8711
8765
|
name: "struere",
|
|
8712
|
-
version: "0.12.
|
|
8766
|
+
version: "0.12.7",
|
|
8713
8767
|
description: "Build, test, and deploy AI agents",
|
|
8714
8768
|
keywords: [
|
|
8715
8769
|
"ai",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const VIRTUAL_MODULE_SOURCE = "\nfunction defineAgent(config) {\n if (!config.name) throw new Error('Agent name is required')\n if (!config.version) throw new Error('Agent version is required')\n if (!config.systemPrompt) throw new Error('System prompt is required')\n return {\n model: {\n model: 'openai/gpt-5-mini',\n temperature: 0.7,\n maxTokens: 4096,\n },\n ...config,\n }\n}\n\nfunction defineRole(config) {\n if (!config.name) throw new Error('Role name is required')\n if (!config.policies || config.policies.length === 0) throw new Error('Role must have at least one policy')\n for (const policy of config.policies) {\n if (!policy.resource) throw new Error('Policy resource is required')\n if (!policy.actions || policy.actions.length === 0) throw new Error('Policy must have at least one action')\n if (!policy.effect) throw new Error('Policy effect is required')\n }\n return {\n ...config,\n scopeRules: config.scopeRules || [],\n fieldMasks: config.fieldMasks || [],\n }\n}\n\nfunction validateObjectProperties(schema, path) {\n if (schema.type === 'object' && !schema.properties) {\n throw new Error('Schema field \"' + path + '\" has type \"object\" but is missing \"properties\". All object fields must declare their properties.')\n }\n if (schema.properties) {\n for (const [key, value] of Object.entries(schema.properties)) {\n validateObjectProperties(value, path ? path + '.' + key : key)\n }\n }\n if (schema.items) {\n validateObjectProperties(schema.items, path + '[]')\n }\n}\n\nfunction defineData(config) {\n if (!config.name) throw new Error('Data type name is required')\n if (!config.slug) throw new Error('Data type slug is required')\n if (!config.schema) throw new Error('Data type schema is required')\n if (config.schema.type !== 'object') throw new Error('Data type schema must be an object type')\n if (config.schema.properties) {\n for (const [key, value] of Object.entries(config.schema.properties)) {\n validateObjectProperties(value, key)\n }\n }\n if (config.boundToRole !== undefined && config.boundToRole === '') throw new Error('boundToRole cannot be an empty string')\n if (config.userIdField !== undefined && !config.boundToRole) throw new Error('userIdField requires boundToRole to be set')\n const userIdField = config.boundToRole && !config.userIdField ? 'userId' : config.userIdField\n return {\n ...config,\n searchFields: config.searchFields || [],\n userIdField,\n }\n}\n\nfunction defineTrigger(config) {\n const VALID_ACTIONS = ['created', 'updated', 'deleted']\n if (!config.name) throw new Error('Trigger name is required')\n if (!config.slug) throw new Error('Trigger slug is required')\n if (!config.on) throw new Error('Trigger \"on\" configuration is required')\n if (config.on.schedule) {\n const parts = config.on.schedule.trim().split(/s+/)\n if (parts.length !== 5) throw new Error('Invalid cron expression: expected 5 fields, got ' + parts.length)\n } else {\n if (!config.on.entityType) throw new Error('Trigger entityType is required')\n if (!config.on.action || !VALID_ACTIONS.includes(config.on.action)) throw new Error('Trigger action must be one of: ' + VALID_ACTIONS.join(', '))\n }\n if (!config.actions || config.actions.length === 0) throw new Error('Trigger must have at least one action')\n for (const action of config.actions) {\n if (!action.tool) throw new Error('Trigger action tool is required')\n if (!action.args || typeof action.args !== 'object') throw new Error('Trigger action args must be an object')\n }\n if (config.schedule) {\n if (config.schedule.delay !== undefined && config.schedule.at !== undefined) throw new Error('Trigger schedule cannot have both \"delay\" and \"at\"')\n if (config.schedule.delay !== undefined && typeof config.schedule.delay !== 'number') throw new Error('Trigger schedule.delay must be a number')\n if (config.schedule.at !== undefined && typeof config.schedule.at !== 'string') throw new Error('Trigger schedule.at must be a string')\n }\n if (config.retry) {\n if (config.retry.maxAttempts !== undefined && (typeof config.retry.maxAttempts !== 'number' || config.retry.maxAttempts < 1)) throw new Error('Trigger retry.maxAttempts must be a positive number')\n if (config.retry.backoffMs !== undefined && (typeof config.retry.backoffMs !== 'number' || config.retry.backoffMs < 0)) throw new Error('Trigger retry.backoffMs must be a non-negative number')\n }\n return config\n}\n\nfunction wrapHandler(name, handler) {\n return async (params, context, struere, fetch) => {\n try {\n return await handler(params, context, struere, fetch)\n } catch (error) {\n console.error('Tool \"' + name + '\" execution error:', error)\n throw error\n }\n }\n}\n\nfunction defineTools(tools) {\n return tools.map((tool) => {\n if (!tool.name) throw new Error('Tool name is required')\n if (!tool.description) throw new Error('Tool \"' + tool.name + '\" requires a description')\n if (!tool.parameters) throw new Error('Tool \"' + tool.name + '\" requires parameters definition')\n if (typeof tool.handler !== 'function') throw new Error('Tool \"' + tool.name + '\" requires a handler function')\n return {\n name: tool.name,\n description: tool.description,\n parameters: tool.parameters,\n handler: wrapHandler(tool.name, tool.handler),\n _originalHandler: tool.handler,\n templateOnly: tool.templateOnly,\n }\n })\n}\n\nfunction defineEntityType() {\n throw new Error('defineEntityType has been renamed to defineData. Please update your imports: import { defineData } from \"struere\"')\n}\n\nexport { defineAgent, defineRole, defineData, defineEntityType, defineTrigger, defineTools }\n";
|
|
1
|
+
export declare const VIRTUAL_MODULE_SOURCE = "\nfunction defineAgent(config) {\n if (!config.name) throw new Error('Agent name is required')\n if (!config.version) throw new Error('Agent version is required')\n if (!config.systemPrompt) throw new Error('System prompt is required')\n return {\n model: {\n model: 'openai/gpt-5-mini',\n temperature: 0.7,\n maxTokens: 4096,\n },\n ...config,\n }\n}\n\nfunction defineRole(config) {\n if (!config.name) throw new Error('Role name is required')\n if (!config.policies || config.policies.length === 0) throw new Error('Role must have at least one policy')\n for (const policy of config.policies) {\n if (!policy.resource) throw new Error('Policy resource is required')\n if (!policy.actions || policy.actions.length === 0) throw new Error('Policy must have at least one action')\n if (!policy.effect) throw new Error('Policy effect is required')\n }\n return {\n ...config,\n scopeRules: config.scopeRules || [],\n fieldMasks: config.fieldMasks || [],\n }\n}\n\nfunction validateObjectProperties(schema, path) {\n if (schema.type === 'object' && !schema.properties) {\n throw new Error('Schema field \"' + path + '\" has type \"object\" but is missing \"properties\". All object fields must declare their properties.')\n }\n if (schema.properties) {\n for (const [key, value] of Object.entries(schema.properties)) {\n validateObjectProperties(value, path ? path + '.' + key : key)\n }\n }\n if (schema.items) {\n validateObjectProperties(schema.items, path + '[]')\n }\n}\n\nfunction defineData(config) {\n if (!config.name) throw new Error('Data type name is required')\n if (!config.slug) throw new Error('Data type slug is required')\n if (!config.schema) throw new Error('Data type schema is required')\n if (config.schema.type !== 'object') throw new Error('Data type schema must be an object type')\n if (config.schema.properties) {\n for (const [key, value] of Object.entries(config.schema.properties)) {\n validateObjectProperties(value, key)\n }\n }\n if (config.boundToRole !== undefined && config.boundToRole === '') throw new Error('boundToRole cannot be an empty string')\n if (config.userIdField !== undefined && !config.boundToRole) throw new Error('userIdField requires boundToRole to be set')\n const userIdField = config.boundToRole && !config.userIdField ? 'userId' : config.userIdField\n return {\n ...config,\n searchFields: config.searchFields || [],\n userIdField,\n }\n}\n\nfunction defineTrigger(config) {\n const VALID_ACTIONS = ['created', 'updated', 'deleted']\n if (!config.name) throw new Error('Trigger name is required')\n if (!config.slug) throw new Error('Trigger slug is required')\n if (!config.on) throw new Error('Trigger \"on\" configuration is required')\n if (config.on.schedule) {\n const parts = config.on.schedule.trim().split(/s+/)\n if (parts.length !== 5) throw new Error('Invalid cron expression: expected 5 fields, got ' + parts.length)\n } else {\n if (!config.on.entityType) throw new Error('Trigger entityType is required')\n if (!config.on.action || !VALID_ACTIONS.includes(config.on.action)) throw new Error('Trigger action must be one of: ' + VALID_ACTIONS.join(', '))\n }\n if (!config.actions || config.actions.length === 0) throw new Error('Trigger must have at least one action')\n for (const action of config.actions) {\n if (!action.tool) throw new Error('Trigger action tool is required')\n if (!action.args || typeof action.args !== 'object') throw new Error('Trigger action args must be an object')\n }\n if (config.schedule) {\n if (config.schedule.delay !== undefined && config.schedule.at !== undefined) throw new Error('Trigger schedule cannot have both \"delay\" and \"at\"')\n if (config.schedule.delay !== undefined && typeof config.schedule.delay !== 'number') throw new Error('Trigger schedule.delay must be a number')\n if (config.schedule.at !== undefined && typeof config.schedule.at !== 'string') throw new Error('Trigger schedule.at must be a string')\n }\n if (config.retry) {\n if (config.retry.maxAttempts !== undefined && (typeof config.retry.maxAttempts !== 'number' || config.retry.maxAttempts < 1)) throw new Error('Trigger retry.maxAttempts must be a positive number')\n if (config.retry.backoffMs !== undefined && (typeof config.retry.backoffMs !== 'number' || config.retry.backoffMs < 0)) throw new Error('Trigger retry.backoffMs must be a non-negative number')\n }\n return config\n}\n\nfunction wrapHandler(name, handler) {\n return async (params, context, struere, fetch) => {\n try {\n return await handler(params, context, struere, fetch)\n } catch (error) {\n console.error('Tool \"' + name + '\" execution error:', error)\n throw error\n }\n }\n}\n\nfunction defineTools(tools) {\n return tools.map((tool) => {\n if (!tool.name) throw new Error('Tool name is required')\n if (!tool.description) throw new Error('Tool \"' + tool.name + '\" requires a description')\n if (!tool.parameters) throw new Error('Tool \"' + tool.name + '\" requires parameters definition')\n if (typeof tool.handler !== 'function') throw new Error('Tool \"' + tool.name + '\" requires a handler function')\n return {\n name: tool.name,\n description: tool.description,\n parameters: tool.parameters,\n handler: wrapHandler(tool.name, tool.handler),\n _originalHandler: tool.handler,\n templateOnly: tool.templateOnly,\n }\n })\n}\n\nfunction defineRouter(config) {\n const VALID_OPERATORS = ['eq', 'neq', 'in', 'contains', 'regex', 'gt', 'lt', 'exists']\n if (!config.name) throw new Error('Router name is required')\n if (!config.slug) throw new Error('Router slug is required')\n if (!config.agents || config.agents.length === 0) throw new Error('Router must have at least one agent')\n var agentSlugs = new Set(config.agents.map(function(a) { return a.slug }))\n if (!agentSlugs.has(config.fallback)) throw new Error('Router fallback \"' + config.fallback + '\" must reference an agent slug in the agents array')\n if (config.mode === 'rules') {\n if (!config.rules || config.rules.length === 0) throw new Error('Router with mode \"rules\" must have at least one rule')\n for (var rule of config.rules) {\n if (!rule.conditions || rule.conditions.length === 0) throw new Error('Each router rule must have at least one condition')\n if (!agentSlugs.has(rule.route)) throw new Error('Router rule route \"' + rule.route + '\" must reference an agent slug in the agents array')\n for (var condition of rule.conditions) {\n if (!condition.field) throw new Error('Router rule condition field is required')\n if (!VALID_OPERATORS.includes(condition.operator)) throw new Error('Router rule condition operator must be one of: ' + VALID_OPERATORS.join(', '))\n }\n }\n }\n return config\n}\n\nfunction defineEntityType() {\n throw new Error('defineEntityType has been renamed to defineData. Please update your imports: import { defineData } from \"struere\"')\n}\n\nexport { defineAgent, defineRole, defineData, defineEntityType, defineTrigger, defineTools, defineRouter }\n";
|
|
2
2
|
export declare function registerStruerePlugin(): void;
|
|
3
3
|
export declare function generateTypeDeclarations(cwd: string): void;
|
|
4
4
|
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/plugin.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,qBAAqB
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/plugin.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,qBAAqB,0jOAmJjC,CAAA;AAED,wBAAgB,qBAAqB,IAAI,IAAI,CAkB5C;AA8OD,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAkB1D"}
|