@takeshape/schema 11.99.0 → 11.99.2

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/agents.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AgentJSON, AgentMap, GuardJSON, ProjectSchemaJSON, QueryJSON } from './project-schema/index.ts';
1
+ import type { AgentJSON, AgentMap, GuardJSON, GuardMap, ProjectSchemaJSON, QueryJSON } from './project-schema/index.ts';
2
2
  export declare const START_AGENT_EXECUTION = "START";
3
3
  /**
4
4
  * Special transition destination ID for agent transitions that end the agent execution.
@@ -27,9 +27,12 @@ export declare const AGENTS_SCHEMA_PATH: readonly ["ai-experimental", "agents"];
27
27
  * Check if a guard is enabled.
28
28
  */
29
29
  export declare const isGuardEnabled: (guard: GuardJSON | undefined) => boolean;
30
+ export declare function getGuardMap(schema: ProjectSchemaJSON): GuardMap | undefined;
30
31
  export declare function getGuards(schema: ProjectSchemaJSON): (GuardJSON & {
31
32
  id: string;
32
33
  })[];
34
+ export declare function setGuardMap<S extends Partial<ProjectSchemaJSON>>(schema: S, guards: GuardMap): S;
35
+ export declare function setGuard<S extends Partial<ProjectSchemaJSON>>(schema: S, id: string, guard: GuardJSON): S;
33
36
  /**
34
37
  * Get a guard configuration from the project schema.
35
38
  */
@@ -38,7 +41,12 @@ export declare function getGuardConfig(schema: ProjectSchemaJSON, guardId: strin
38
41
  * Get a guard configuration from the project schema, but only if it is enabled.
39
42
  */
40
43
  export declare function getEnabledGuardConfig(schema: ProjectSchemaJSON, guardId: string): GuardJSON | undefined;
41
- export declare function getAgentMap(projectSchema: ProjectSchemaJSON): AgentMap | undefined;
44
+ export declare function getAgentMap(projectSchema: Pick<ProjectSchemaJSON, 'ai-experimental'>): AgentMap | undefined;
45
+ export declare function getAgents(projectSchema: Pick<ProjectSchemaJSON, 'ai-experimental'>): (AgentJSON & {
46
+ name: string;
47
+ })[] | undefined;
48
+ export declare function setAgentMap<S extends Partial<ProjectSchemaJSON>>(projectSchema: S, agents: AgentMap): S;
49
+ export declare function setAgent<S extends Partial<ProjectSchemaJSON>>(projectSchema: S, name: string, agent: AgentJSON): S;
42
50
  export declare function getAgent(projectSchema: ProjectSchemaJSON, name: string): AgentJSON | undefined;
43
51
  export declare function ensureAgent(projectSchema: ProjectSchemaJSON, name: string): AgentJSON;
44
52
  export declare function isAgentQuery(query: QueryJSON, agentName: string): boolean;
package/dist/agents.js CHANGED
@@ -1,3 +1,4 @@
1
+ import set from 'lodash/fp/set.js';
1
2
  import get from 'lodash/get.js';
2
3
  import uniq from 'lodash/uniq.js';
3
4
  import upperFirst from 'lodash/upperFirst.js';
@@ -144,10 +145,19 @@ export const AGENTS_SCHEMA_PATH = ['ai-experimental', 'agents'];
144
145
  export const isGuardEnabled = (guard) => {
145
146
  return Boolean(guard && guard.enabled !== false);
146
147
  };
148
+ export function getGuardMap(schema) {
149
+ return schema['ai-experimental']?.guards;
150
+ }
147
151
  export function getGuards(schema) {
148
- const guards = schema['ai-experimental']?.guards;
152
+ const guards = getGuardMap(schema);
149
153
  return guards ? Object.entries(guards).map(([id, guard]) => ({ id, ...guard })) : [];
150
154
  }
155
+ export function setGuardMap(schema, guards) {
156
+ return set(GUARDS_SCHEMA_PATH, guards, schema);
157
+ }
158
+ export function setGuard(schema, id, guard) {
159
+ return set([...GUARDS_SCHEMA_PATH, id], guard, schema);
160
+ }
151
161
  /**
152
162
  * Get a guard configuration from the project schema.
153
163
  */
@@ -166,6 +176,16 @@ export function getEnabledGuardConfig(schema, guardId) {
166
176
  export function getAgentMap(projectSchema) {
167
177
  return projectSchema['ai-experimental']?.agents;
168
178
  }
179
+ export function getAgents(projectSchema) {
180
+ const agentMap = getAgentMap(projectSchema);
181
+ return agentMap && Object.entries(agentMap).map(([name, agent]) => ({ name, ...agent }));
182
+ }
183
+ export function setAgentMap(projectSchema, agents) {
184
+ return set(AGENTS_SCHEMA_PATH, agents, projectSchema);
185
+ }
186
+ export function setAgent(projectSchema, name, agent) {
187
+ return set([...AGENTS_SCHEMA_PATH, name], agent, projectSchema);
188
+ }
169
189
  export function getAgent(projectSchema, name) {
170
190
  return getAgentMap(projectSchema)?.[name];
171
191
  }
package/dist/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export * from './get-is-leaf.ts';
11
11
  export * from './interfaces.ts';
12
12
  export * from './migration/index.ts';
13
13
  export type { ProjectSchemaUpdate } from './migration/types.ts';
14
+ export { AGENTS_UPDATE_KEY, GUARDS_UPDATE_KEY, MCP_TOOLS_UPDATE_KEY } from './migration/types.ts';
14
15
  export * from './mocks.ts';
15
16
  export * from './models/runtime-schema.ts';
16
17
  export * from './models/user-schema.ts';
package/dist/index.js CHANGED
@@ -9,6 +9,7 @@ export * from "./flatten-templates.js";
9
9
  export * from "./get-is-leaf.js";
10
10
  export * from "./interfaces.js";
11
11
  export * from "./migration/index.js";
12
+ export { AGENTS_UPDATE_KEY, GUARDS_UPDATE_KEY, MCP_TOOLS_UPDATE_KEY } from "./migration/types.js";
12
13
  export * from "./mocks.js";
13
14
  export * from "./models/runtime-schema.js";
14
15
  export * from "./models/user-schema.js";
@@ -5,13 +5,16 @@ export type ProjectSchemaMigrationContext = {
5
5
  encryptFn: EncryptFn;
6
6
  decryptFn: SafeDecryptFn;
7
7
  };
8
+ export declare const AGENTS_UPDATE_KEY = "ai-experimental.agents";
9
+ export declare const GUARDS_UPDATE_KEY = "ai-experimental.guards";
10
+ export declare const MCP_TOOLS_UPDATE_KEY = "ai-experimental.mcp.tools";
8
11
  export type ProjectSchemaUpdate = {
9
12
  queries?: Record<string, QueryJSON | null>;
10
13
  mutations?: Record<string, QueryJSON | null>;
11
14
  shapes?: Record<string, ShapeJSON | null>;
12
- 'ai-experimental.agents'?: Record<string, AgentJSON | null>;
13
- 'ai-experimental.guards'?: Record<string, GuardJSON | null>;
14
- 'ai-experimental.mcp.tools'?: Record<string, ToolJSON | null>;
15
+ [AGENTS_UPDATE_KEY]?: Record<string, AgentJSON | null>;
16
+ [GUARDS_UPDATE_KEY]?: Record<string, GuardJSON | null>;
17
+ [MCP_TOOLS_UPDATE_KEY]?: Record<string, ToolJSON | null>;
15
18
  forms?: Record<string, FormConfig | null>;
16
19
  workflows?: Record<string, Workflow | null>;
17
20
  services?: Record<string, ServiceConfigJSON | null>;
@@ -1 +1,3 @@
1
- export {};
1
+ export const AGENTS_UPDATE_KEY = 'ai-experimental.agents';
2
+ export const GUARDS_UPDATE_KEY = 'ai-experimental.guards';
3
+ export const MCP_TOOLS_UPDATE_KEY = 'ai-experimental.mcp.tools';
package/dist/refs.js CHANGED
@@ -526,7 +526,7 @@ export function getAllPropertyRefs(projectSchema) {
526
526
  return false;
527
527
  }
528
528
  const parent = get(projectSchema, path.slice(0, -1));
529
- return isRecord(parent) && parent.type === 'generate';
529
+ return isRecord(parent) && (parent.type === 'generate' || parent.type === 'chat');
530
530
  };
531
531
  const pushRef = (refStr) => {
532
532
  const parsed = parsePropertyRef(refStr);
@@ -6,6 +6,7 @@ import isString from 'lodash/isString.js';
6
6
  import keyBy from 'lodash/keyBy.js';
7
7
  import mapValues from 'lodash/mapValues.js';
8
8
  import uniq from 'lodash/uniq.js';
9
+ import { AGENTS_SCHEMA_PATH, getAgentMap } from './agents.js';
9
10
  import { workflowsEnabled } from "./api-version.js";
10
11
  import { builtInForms, builtInShapes } from "./builtin-schema.js";
11
12
  import { SERVICE_OBJECT_PATTERN_NAME } from "./constants.js";
@@ -711,10 +712,10 @@ export function getAllRefsInShapes(projectSchema, predicate) {
711
712
  }
712
713
  export function getRefsInAgents(context, predicate) {
713
714
  const refs = [];
714
- const agents = context['ai-experimental']?.agents;
715
+ const agents = getAgentMap(context);
715
716
  if (agents) {
716
717
  for (const [agentKey, agent] of Object.entries(agents)) {
717
- const agentPath = ['services', 'ai-experimental', 'agents', agentKey];
718
+ const agentPath = [...AGENTS_SCHEMA_PATH, agentKey];
718
719
  agent.api.inputs.forEach((input, index) => {
719
720
  const ref = {
720
721
  ...parseRef(context, input.args),
@@ -4,5 +4,5 @@ export declare function getMcpToolMap(projectSchema: ProjectSchemaJSON): ToolMap
4
4
  export declare function getMcpTools(projectSchema: ProjectSchemaJSON): ToolJSON[] | undefined;
5
5
  export declare function getMcpToolNames(projectSchema: ProjectSchemaJSON): string[];
6
6
  export declare function getMcpTool(projectSchema: ProjectSchemaJSON, toolName: string): ToolJSON | undefined;
7
- export declare function setMcpToolMap<S extends ProjectSchemaJSON>(projectSchema: S, tools: ToolMap): S;
8
- export declare function setMcpTool<S extends ProjectSchemaJSON>(projectSchema: S, tool: ToolJSON): S;
7
+ export declare function setMcpToolMap<S extends Partial<ProjectSchemaJSON>>(projectSchema: S, tools: ToolMap): S;
8
+ export declare function setMcpTool<S extends Partial<ProjectSchemaJSON>>(projectSchema: S, tool: ToolJSON): S;
@@ -1,4 +1,4 @@
1
- import type { ProjectSchemaUpdate } from '../migration/types.ts';
1
+ import { type ProjectSchemaUpdate } from '../migration/types.ts';
2
2
  import type { ProjectSchemaJSON } from '../project-schema/index.ts';
3
3
  /**
4
4
  * Apply a schema update to a schema. This can operate on a schema with frozen properties,
@@ -2,6 +2,7 @@ import set from 'lodash/fp/set.js';
2
2
  import get from 'lodash/get.js';
3
3
  import omit from 'lodash/omit.js';
4
4
  import unset from 'lodash/unset.js';
5
+ import { AGENTS_UPDATE_KEY, GUARDS_UPDATE_KEY, MCP_TOOLS_UPDATE_KEY } from "../migration/types.js";
5
6
  /**
6
7
  * Array of lodash.get paths to keys that are merged when applying a schema update.
7
8
  */
@@ -12,9 +13,9 @@ const schemaUpdateMergedKeys = [
12
13
  'workflows',
13
14
  'forms',
14
15
  'services',
15
- 'ai-experimental.agents',
16
- 'ai-experimental.guards',
17
- 'ai-experimental.mcp.tools'
16
+ AGENTS_UPDATE_KEY,
17
+ GUARDS_UPDATE_KEY,
18
+ MCP_TOOLS_UPDATE_KEY
18
19
  ];
19
20
  function shallowMerge(original, update) {
20
21
  const result = { ...original };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takeshape/schema",
3
- "version": "11.99.0",
3
+ "version": "11.99.2",
4
4
  "description": "TakeShape Schema",
5
5
  "homepage": "https://www.takeshape.io",
6
6
  "repository": {
@@ -58,9 +58,9 @@
58
58
  "p-reduce": "^2.1.0",
59
59
  "semver": "^7.3.2",
60
60
  "tiny-invariant": "^1.2.0",
61
- "@takeshape/errors": "11.99.0",
62
- "@takeshape/json-schema": "11.99.0",
63
- "@takeshape/util": "11.99.0"
61
+ "@takeshape/errors": "11.99.2",
62
+ "@takeshape/json-schema": "11.99.2",
63
+ "@takeshape/util": "11.99.2"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@takeshape/json-schema-to-typescript": "^11.0.0",
@@ -76,7 +76,7 @@
76
76
  "glob": "^7.1.6",
77
77
  "json-schema-to-ts": "^3.1.1",
78
78
  "shortid": "^2.2.15",
79
- "@takeshape/infra": "11.99.0"
79
+ "@takeshape/infra": "11.99.2"
80
80
  },
81
81
  "engines": {
82
82
  "node": ">=20"