@sprinterai/runtime 0.5.0 → 0.7.1
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/agent/execute-agent.d.ts +5 -8
- package/dist/agent/execute-agent.d.ts.map +1 -1
- package/dist/agent/execute-agent.js +2 -3
- package/dist/agent/execute-agent.js.map +1 -1
- package/dist/chat/chat-handler.d.ts +2 -0
- package/dist/chat/chat-handler.d.ts.map +1 -1
- package/dist/chat/chat-handler.js +15 -12
- package/dist/chat/chat-handler.js.map +1 -1
- package/dist/chat/chat-handler.test.js +1 -0
- package/dist/chat/chat-handler.test.js.map +1 -1
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/inngest/create-extraction-functions.d.ts +71 -0
- package/dist/inngest/create-extraction-functions.d.ts.map +1 -0
- package/dist/inngest/create-extraction-functions.js +71 -0
- package/dist/inngest/create-extraction-functions.js.map +1 -0
- package/dist/inngest/event-names.d.ts +20 -0
- package/dist/inngest/event-names.d.ts.map +1 -0
- package/dist/inngest/event-names.js +19 -0
- package/dist/inngest/event-names.js.map +1 -0
- package/dist/inngest/index.d.ts +5 -0
- package/dist/inngest/index.d.ts.map +1 -0
- package/dist/inngest/index.js +3 -0
- package/dist/inngest/index.js.map +1 -0
- package/dist/package-exports.test.d.ts +2 -0
- package/dist/package-exports.test.d.ts.map +1 -0
- package/dist/package-exports.test.js +36 -0
- package/dist/package-exports.test.js.map +1 -0
- package/dist/testing/in-memory-chat-store.d.ts +4 -3
- package/dist/testing/in-memory-chat-store.d.ts.map +1 -1
- package/dist/testing/in-memory-chat-store.js +1 -1
- package/dist/testing/in-memory-chat-store.js.map +1 -1
- package/dist/tool/entity-tools-factory.d.ts.map +1 -1
- package/dist/tool/entity-tools-factory.js +80 -0
- package/dist/tool/entity-tools-factory.js.map +1 -1
- package/dist/tool/entity-tools-factory.test.js +68 -2
- package/dist/tool/entity-tools-factory.test.js.map +1 -1
- package/dist/tool/gallery/gallery-module.d.ts +4 -0
- package/dist/tool/gallery/gallery-module.d.ts.map +1 -0
- package/dist/tool/gallery/gallery-module.js +10 -0
- package/dist/tool/gallery/gallery-module.js.map +1 -0
- package/dist/tool/gallery/gallery-tool-definitions.d.ts +17 -0
- package/dist/tool/gallery/gallery-tool-definitions.d.ts.map +1 -0
- package/dist/tool/gallery/gallery-tool-definitions.js +748 -0
- package/dist/tool/gallery/gallery-tool-definitions.js.map +1 -0
- package/dist/tool/gallery/gallery-tools.d.ts +11 -0
- package/dist/tool/gallery/gallery-tools.d.ts.map +1 -0
- package/dist/tool/gallery/gallery-tools.js +971 -0
- package/dist/tool/gallery/gallery-tools.js.map +1 -0
- package/dist/tool/gallery/gallery-tools.test.d.ts +2 -0
- package/dist/tool/gallery/gallery-tools.test.d.ts.map +1 -0
- package/dist/tool/gallery/gallery-tools.test.js +75 -0
- package/dist/tool/gallery/gallery-tools.test.js.map +1 -0
- package/dist/tool/gallery/index.d.ts +5 -0
- package/dist/tool/gallery/index.d.ts.map +1 -0
- package/dist/tool/gallery/index.js +4 -0
- package/dist/tool/gallery/index.js.map +1 -0
- package/dist/tool/index.d.ts +9 -7
- package/dist/tool/index.d.ts.map +1 -1
- package/dist/tool/index.js +6 -5
- package/dist/tool/index.js.map +1 -1
- package/dist/tool/tool-registry.d.ts +1 -1
- package/dist/tool/tool-registry.d.ts.map +1 -1
- package/dist/tool/tool-registry.js +1 -0
- package/dist/tool/tool-registry.js.map +1 -1
- package/dist/tool/tool-registry.test.js +7 -0
- package/dist/tool/tool-registry.test.js.map +1 -1
- package/dist/workflow/create-node-executor.d.ts +40 -0
- package/dist/workflow/create-node-executor.d.ts.map +1 -0
- package/dist/workflow/create-node-executor.js +234 -0
- package/dist/workflow/create-node-executor.js.map +1 -0
- package/dist/workflow/field-recovery.d.ts +12 -0
- package/dist/workflow/field-recovery.d.ts.map +1 -0
- package/dist/workflow/field-recovery.js +86 -0
- package/dist/workflow/field-recovery.js.map +1 -0
- package/dist/workflow/index.d.ts +5 -0
- package/dist/workflow/index.d.ts.map +1 -1
- package/dist/workflow/index.js +3 -0
- package/dist/workflow/index.js.map +1 -1
- package/dist/workflow/run-entity-workflow.d.ts +53 -0
- package/dist/workflow/run-entity-workflow.d.ts.map +1 -0
- package/dist/workflow/run-entity-workflow.js +72 -0
- package/dist/workflow/run-entity-workflow.js.map +1 -0
- package/package.json +123 -3
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attempt to parse a structured value from an agent's text response.
|
|
3
|
+
* Used as a fallback when the agent completes without calling submitValue.
|
|
4
|
+
*
|
|
5
|
+
* Handles: JSON code blocks, raw JSON, enum matching, number/boolean extraction.
|
|
6
|
+
*/
|
|
7
|
+
export function extractValueFromText(text, schemaProperty) {
|
|
8
|
+
const trimmed = text.trim();
|
|
9
|
+
// Try JSON code block first
|
|
10
|
+
const jsonBlockMatch = trimmed.match(/```(?:json)?\s*\n?([\s\S]*?)\n?```/);
|
|
11
|
+
if (jsonBlockMatch) {
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(jsonBlockMatch[1].trim());
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
// Fall through
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
// Try parsing whole response as JSON
|
|
20
|
+
try {
|
|
21
|
+
const parsed = JSON.parse(trimmed);
|
|
22
|
+
if (parsed !== null && typeof parsed !== 'undefined') {
|
|
23
|
+
if (typeof parsed === 'object' &&
|
|
24
|
+
!Array.isArray(parsed) &&
|
|
25
|
+
schemaProperty?.type !== 'object') {
|
|
26
|
+
const wrapper = parsed;
|
|
27
|
+
const scalarKey = ['value', 'result', 'answer', 'response'].find((k) => k in wrapper);
|
|
28
|
+
if (scalarKey !== undefined)
|
|
29
|
+
return wrapper[scalarKey];
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return parsed;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// Not JSON
|
|
38
|
+
}
|
|
39
|
+
// Enum matching
|
|
40
|
+
const enumValues = schemaProperty?.enum;
|
|
41
|
+
if (enumValues && enumValues.length > 0) {
|
|
42
|
+
const lowerText = trimmed.toLowerCase();
|
|
43
|
+
for (const enumVal of enumValues) {
|
|
44
|
+
if (lowerText.includes(enumVal.toLowerCase()))
|
|
45
|
+
return enumVal;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Number extraction
|
|
49
|
+
const schemaType = schemaProperty?.type;
|
|
50
|
+
if (schemaType === 'number' || schemaType === 'integer') {
|
|
51
|
+
const numberMatch = trimmed.match(/-?\d[\d,]*\.?\d*/);
|
|
52
|
+
if (numberMatch) {
|
|
53
|
+
const num = Number(numberMatch[0].replace(/,/g, ''));
|
|
54
|
+
if (!isNaN(num))
|
|
55
|
+
return num;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Boolean extraction
|
|
59
|
+
if (schemaType === 'boolean') {
|
|
60
|
+
const lower = trimmed.toLowerCase();
|
|
61
|
+
if (/\b(false|no)\b/.test(lower))
|
|
62
|
+
return false;
|
|
63
|
+
if (/\b(true|yes)\b/.test(lower))
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
// Short text — use as string value
|
|
67
|
+
if (trimmed.length <= 2000)
|
|
68
|
+
return trimmed;
|
|
69
|
+
// Long text — try last line
|
|
70
|
+
const lines = trimmed.split('\n').filter((l) => l.trim());
|
|
71
|
+
const lastLine = lines[lines.length - 1]?.trim();
|
|
72
|
+
if (lastLine && lastLine.length <= 500)
|
|
73
|
+
return lastLine;
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Check if a field value is "empty" for workflow purposes.
|
|
78
|
+
*/
|
|
79
|
+
export function isEmptyFieldValue(value) {
|
|
80
|
+
if (value === null || value === undefined || value === '')
|
|
81
|
+
return true;
|
|
82
|
+
if (Array.isArray(value) && value.length === 0)
|
|
83
|
+
return true;
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=field-recovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field-recovery.js","sourceRoot":"","sources":["../../src/workflow/field-recovery.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAClC,IAAY,EACZ,cAAwC;IAExC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IAE5B,4BAA4B;IAC5B,MAAM,cAAc,GAAG,OAAO,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;IAC3E,IAAI,cAAc,EAAE,CAAC;QACnB,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAC9C,CAAC;QAAC,MAAM,CAAC;YACP,eAAe;QACjB,CAAC;IACH,CAAC;IAED,qCAAqC;IACrC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACnC,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;YACrD,IACE,OAAO,MAAM,KAAK,QAAQ;gBAC1B,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;gBACtB,cAAc,EAAE,IAAI,KAAK,QAAQ,EACjC,CAAC;gBACD,MAAM,OAAO,GAAG,MAAiC,CAAC;gBAClD,MAAM,SAAS,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC;gBACtF,IAAI,SAAS,KAAK,SAAS;oBAAE,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC;YACzD,CAAC;iBA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AO,CAAC;IAE3C,4BAA4B;IAC5B,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1D,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;IACjD,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG;QAAE,OAAO,QAAQ,CAAC;IAExD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAc;IAC9C,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE;QAAE,OAAO,IAAI,CAAC;IACvE,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAC5D,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/workflow/index.d.ts
CHANGED
|
@@ -6,4 +6,9 @@ export type { NodeStatusUpdate } from './evaluate-nodes.js';
|
|
|
6
6
|
export { runWorkflow } from './workflow-runner.js';
|
|
7
7
|
export type { RunWorkflowOptions, RunWorkflowResult } from './workflow-runner.js';
|
|
8
8
|
export type { NodeExecutionContext, NodeExecutionResult, NodeExecutorFn } from './node-executor.js';
|
|
9
|
+
export { extractValueFromText, isEmptyFieldValue } from './field-recovery.js';
|
|
10
|
+
export { createNodeExecutor } from './create-node-executor.js';
|
|
11
|
+
export type { CreateNodeExecutorOptions } from './create-node-executor.js';
|
|
12
|
+
export { runEntityWorkflow } from './run-entity-workflow.js';
|
|
13
|
+
export type { RunEntityWorkflowOptions } from './run-entity-workflow.js';
|
|
9
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/workflow/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC/E,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AACzE,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,YAAY,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,YAAY,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/workflow/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC/E,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AACzE,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,YAAY,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,YAAY,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjG,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,YAAY,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,YAAY,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/workflow/index.js
CHANGED
|
@@ -2,4 +2,7 @@ export { compileEntityWorkflowDefinition, getWorkflowLayers } from './compile.js
|
|
|
2
2
|
export { computeWorkflowProgress, deriveWorkflowStatus } from './status.js';
|
|
3
3
|
export { evaluateNodeStatuses } from './evaluate-nodes.js';
|
|
4
4
|
export { runWorkflow } from './workflow-runner.js';
|
|
5
|
+
export { extractValueFromText, isEmptyFieldValue } from './field-recovery.js';
|
|
6
|
+
export { createNodeExecutor } from './create-node-executor.js';
|
|
7
|
+
export { runEntityWorkflow } from './run-entity-workflow.js';
|
|
5
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/workflow/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC/E,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAEzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/workflow/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC/E,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAEzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { EntityStore, EntityTypeRecord, ToolDefinition, WorkflowFieldOverride, WorkflowRunStore, WorkflowTriggerType, EventBus } from '@sprinterai/core';
|
|
2
|
+
import type { LanguageModel } from 'ai';
|
|
3
|
+
import type { ResolveAgentOptions } from '../agent/agent-resolver.js';
|
|
4
|
+
import type { RunWorkflowResult } from './workflow-runner.js';
|
|
5
|
+
/** Options for the high-level entity workflow convenience wrapper. */
|
|
6
|
+
export interface RunEntityWorkflowOptions {
|
|
7
|
+
/** Entity being processed. */
|
|
8
|
+
entityId: string;
|
|
9
|
+
/** Tenant scope. */
|
|
10
|
+
tenantId: string;
|
|
11
|
+
/** The entity type record (provides field configs, json_schema, etc.). */
|
|
12
|
+
entityType: EntityTypeRecord;
|
|
13
|
+
/** Current entity field values. */
|
|
14
|
+
entityContent: Record<string, unknown>;
|
|
15
|
+
/** Store for persisting workflow and node run state. */
|
|
16
|
+
workflowRunStore: WorkflowRunStore;
|
|
17
|
+
/** Entity store for writing extracted values back. */
|
|
18
|
+
entityStore: EntityStore;
|
|
19
|
+
/** Function to resolve a model ID to a LanguageModel instance. */
|
|
20
|
+
resolveModel: (modelId?: string) => LanguageModel;
|
|
21
|
+
/** Options for resolving agents by slug. */
|
|
22
|
+
agentResolverOptions?: ResolveAgentOptions;
|
|
23
|
+
/** All available tools the agent may use. */
|
|
24
|
+
allTools?: ToolDefinition[];
|
|
25
|
+
/** Optional event bus for emitting workflow events. */
|
|
26
|
+
eventBus?: EventBus;
|
|
27
|
+
/** Subset of fields to process. If empty/undefined, process all. */
|
|
28
|
+
fields?: string[];
|
|
29
|
+
/** Force re-extraction even if fields are already populated. */
|
|
30
|
+
force?: boolean;
|
|
31
|
+
/** How this workflow was triggered. */
|
|
32
|
+
triggerType?: WorkflowTriggerType;
|
|
33
|
+
/** Who triggered this workflow (userId, agentSlug, etc.). */
|
|
34
|
+
triggeredBy?: string;
|
|
35
|
+
/** Per-field instruction overrides. */
|
|
36
|
+
fieldOverrides?: Record<string, WorkflowFieldOverride>;
|
|
37
|
+
/** Max agent loop iterations per field (default: 5). */
|
|
38
|
+
maxSteps?: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Run an entity extraction workflow end-to-end.
|
|
42
|
+
*
|
|
43
|
+
* This is a high-level convenience wrapper that:
|
|
44
|
+
* 1. Reads field configs from the entity type record
|
|
45
|
+
* 2. Gets schema properties from the entity type's json_schema
|
|
46
|
+
* 3. Compiles the workflow definition via compileEntityWorkflowDefinition()
|
|
47
|
+
* 4. Creates a node executor via createNodeExecutor()
|
|
48
|
+
* 5. Calls runWorkflow() with everything assembled
|
|
49
|
+
*
|
|
50
|
+
* Consumers call one function instead of assembling 5 pieces.
|
|
51
|
+
*/
|
|
52
|
+
export declare function runEntityWorkflow(options: RunEntityWorkflowOptions): Promise<RunWorkflowResult>;
|
|
53
|
+
//# sourceMappingURL=run-entity-workflow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-entity-workflow.d.ts","sourceRoot":"","sources":["../../src/workflow/run-entity-workflow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACrB,gBAAgB,EAChB,mBAAmB,EACnB,QAAQ,EACT,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAExC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAKnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAI3D,sEAAsE;AACtE,MAAM,WAAW,wBAAwB;IACvC,8BAA8B;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,0EAA0E;IAC1E,UAAU,EAAE,gBAAgB,CAAC;IAC7B,mCAAmC;IACnC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,wDAAwD;IACxD,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,sDAAsD;IACtD,WAAW,EAAE,WAAW,CAAC;IACzB,kEAAkE;IAClE,YAAY,EAAE,CAAC,OAAO,CAAC,EAAE,MAAM,KAAK,aAAa,CAAC;IAClD,4CAA4C;IAC5C,oBAAoB,CAAC,EAAE,mBAAmB,CAAC;IAC3C,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,cAAc,EAAE,CAAC;IAC5B,uDAAuD;IACvD,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,gEAAgE;IAChE,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,uCAAuC;IACvC,WAAW,CAAC,EAAE,mBAAmB,CAAC;IAClC,6DAA6D;IAC7D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uCAAuC;IACvC,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;IACvD,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAID;;;;;;;;;;;GAWG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,iBAAiB,CAAC,CAyF5B"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { compileEntityWorkflowDefinition } from './compile.js';
|
|
2
|
+
import { createNodeExecutor } from './create-node-executor.js';
|
|
3
|
+
import { runWorkflow } from './workflow-runner.js';
|
|
4
|
+
// ─── Main Function ──────────────────────────────────────────────
|
|
5
|
+
/**
|
|
6
|
+
* Run an entity extraction workflow end-to-end.
|
|
7
|
+
*
|
|
8
|
+
* This is a high-level convenience wrapper that:
|
|
9
|
+
* 1. Reads field configs from the entity type record
|
|
10
|
+
* 2. Gets schema properties from the entity type's json_schema
|
|
11
|
+
* 3. Compiles the workflow definition via compileEntityWorkflowDefinition()
|
|
12
|
+
* 4. Creates a node executor via createNodeExecutor()
|
|
13
|
+
* 5. Calls runWorkflow() with everything assembled
|
|
14
|
+
*
|
|
15
|
+
* Consumers call one function instead of assembling 5 pieces.
|
|
16
|
+
*/
|
|
17
|
+
export async function runEntityWorkflow(options) {
|
|
18
|
+
const { entityId, tenantId, entityType, entityContent, workflowRunStore, entityStore, resolveModel: resolveModelFn, agentResolverOptions, allTools = [], eventBus, fields, force, triggerType, triggeredBy, fieldOverrides, maxSteps, } = options;
|
|
19
|
+
// ── 1. Read field configs from entity type ────────────────
|
|
20
|
+
const fieldsConfig = entityType.behaviorJson?.fields ?? entityType.config?.fields ?? {};
|
|
21
|
+
// ── 2. Get schema properties from json_schema ─────────────
|
|
22
|
+
const schemaProperties = entityType.json_schema
|
|
23
|
+
?.properties ?? {};
|
|
24
|
+
// ── 3. Compile the workflow definition ────────────────────
|
|
25
|
+
const definition = compileEntityWorkflowDefinition(entityType);
|
|
26
|
+
// Early return if no extractable fields
|
|
27
|
+
if (definition.nodes.length === 0) {
|
|
28
|
+
return {
|
|
29
|
+
runId: '',
|
|
30
|
+
status: 'completed',
|
|
31
|
+
fieldsExtracted: [],
|
|
32
|
+
errors: {},
|
|
33
|
+
claimedNodeCount: 0,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
// ── 4. Build field extraction configs ─────────────────────
|
|
37
|
+
const fieldExtractionConfigs = {};
|
|
38
|
+
for (const [fieldName, fieldConfig] of Object.entries(fieldsConfig)) {
|
|
39
|
+
if (!fieldConfig.extraction && !fieldConfig.humanInput)
|
|
40
|
+
continue;
|
|
41
|
+
fieldExtractionConfigs[fieldName] = {
|
|
42
|
+
instructions: fieldConfig.extraction?.instructions,
|
|
43
|
+
schemaProperty: schemaProperties[fieldName],
|
|
44
|
+
maxSteps: fieldConfig.extraction?.maxSteps ?? maxSteps,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
// ── 5. Create node executor ───────────────────────────────
|
|
48
|
+
const model = resolveModelFn();
|
|
49
|
+
const executeNode = createNodeExecutor({
|
|
50
|
+
model,
|
|
51
|
+
entityStore,
|
|
52
|
+
agentResolverOptions,
|
|
53
|
+
availableTools: allTools,
|
|
54
|
+
fieldExtractionConfigs,
|
|
55
|
+
});
|
|
56
|
+
// ── 6. Run the workflow ───────────────────────────────────
|
|
57
|
+
return runWorkflow({
|
|
58
|
+
entityId,
|
|
59
|
+
tenantId,
|
|
60
|
+
definition,
|
|
61
|
+
entityContent,
|
|
62
|
+
store: workflowRunStore,
|
|
63
|
+
executeNode,
|
|
64
|
+
eventBus,
|
|
65
|
+
triggerType,
|
|
66
|
+
triggeredBy,
|
|
67
|
+
fields,
|
|
68
|
+
force,
|
|
69
|
+
fieldOverrides,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=run-entity-workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-entity-workflow.js","sourceRoot":"","sources":["../../src/workflow/run-entity-workflow.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,+BAA+B,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAyChD,mEAAmE;AAEnE;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAAiC;IAEjC,MAAM,EACJ,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,YAAY,EAAE,cAAc,EAC5B,oBAAoB,EACpB,QAAQ,GAAG,EAAE,EAC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EAAE,QAAQ;QACxB,sBAAsB;KACvB,CAAC,CAAC;IAEH,6DAA6D;IAC7D,OAAO,WAAW,CAAC;QACjB,QAAQ;QACR,QAAQ;QACR,UAAU;QACV,aAAa;QACb,KAAK,EAAE,gBAAgB;QACvB,WAAW;QACX,QAAQ;QACR,WAAW;QACX,WAAW;QACX,MAAM;QACN,KAAK;QACL,cAAc;KACf,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sprinterai/runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Agent, tool, workflow, and chat runtime engine for the Sprinter AI platform",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -15,49 +15,169 @@
|
|
|
15
15
|
"types": "./dist/agent/index.d.ts",
|
|
16
16
|
"import": "./dist/agent/index.js"
|
|
17
17
|
},
|
|
18
|
+
"./agent/*": {
|
|
19
|
+
"types": "./dist/agent/*.d.ts",
|
|
20
|
+
"import": "./dist/agent/*.js"
|
|
21
|
+
},
|
|
18
22
|
"./tool": {
|
|
19
23
|
"types": "./dist/tool/index.d.ts",
|
|
20
24
|
"import": "./dist/tool/index.js"
|
|
21
25
|
},
|
|
26
|
+
"./tool/*": {
|
|
27
|
+
"types": "./dist/tool/*.d.ts",
|
|
28
|
+
"import": "./dist/tool/*.js"
|
|
29
|
+
},
|
|
22
30
|
"./chat": {
|
|
23
31
|
"types": "./dist/chat/index.d.ts",
|
|
24
32
|
"import": "./dist/chat/index.js"
|
|
25
33
|
},
|
|
34
|
+
"./chat/*": {
|
|
35
|
+
"types": "./dist/chat/*.d.ts",
|
|
36
|
+
"import": "./dist/chat/*.js"
|
|
37
|
+
},
|
|
26
38
|
"./workflow": {
|
|
27
39
|
"types": "./dist/workflow/index.d.ts",
|
|
28
40
|
"import": "./dist/workflow/index.js"
|
|
29
41
|
},
|
|
42
|
+
"./workflow/*": {
|
|
43
|
+
"types": "./dist/workflow/*.d.ts",
|
|
44
|
+
"import": "./dist/workflow/*.js"
|
|
45
|
+
},
|
|
30
46
|
"./scoring": {
|
|
31
47
|
"types": "./dist/scoring/index.d.ts",
|
|
32
48
|
"import": "./dist/scoring/index.js"
|
|
33
49
|
},
|
|
50
|
+
"./scoring/*": {
|
|
51
|
+
"types": "./dist/scoring/*.d.ts",
|
|
52
|
+
"import": "./dist/scoring/*.js"
|
|
53
|
+
},
|
|
34
54
|
"./module": {
|
|
35
55
|
"types": "./dist/module/index.d.ts",
|
|
36
56
|
"import": "./dist/module/index.js"
|
|
37
57
|
},
|
|
58
|
+
"./module/*": {
|
|
59
|
+
"types": "./dist/module/*.d.ts",
|
|
60
|
+
"import": "./dist/module/*.js"
|
|
61
|
+
},
|
|
38
62
|
"./adapters": {
|
|
39
63
|
"types": "./dist/adapters/index.d.ts",
|
|
40
64
|
"import": "./dist/adapters/index.js"
|
|
41
65
|
},
|
|
66
|
+
"./adapters/*": {
|
|
67
|
+
"types": "./dist/adapters/*.d.ts",
|
|
68
|
+
"import": "./dist/adapters/*.js"
|
|
69
|
+
},
|
|
42
70
|
"./eval": {
|
|
43
71
|
"types": "./dist/eval/index.d.ts",
|
|
44
72
|
"import": "./dist/eval/index.js"
|
|
45
73
|
},
|
|
74
|
+
"./eval/*": {
|
|
75
|
+
"types": "./dist/eval/*.d.ts",
|
|
76
|
+
"import": "./dist/eval/*.js"
|
|
77
|
+
},
|
|
46
78
|
"./memory": {
|
|
47
79
|
"types": "./dist/memory/index.d.ts",
|
|
48
80
|
"import": "./dist/memory/index.js"
|
|
49
81
|
},
|
|
82
|
+
"./memory/*": {
|
|
83
|
+
"types": "./dist/memory/*.d.ts",
|
|
84
|
+
"import": "./dist/memory/*.js"
|
|
85
|
+
},
|
|
50
86
|
"./guardrail": {
|
|
51
87
|
"types": "./dist/guardrail/index.d.ts",
|
|
52
88
|
"import": "./dist/guardrail/index.js"
|
|
53
89
|
},
|
|
90
|
+
"./guardrail/*": {
|
|
91
|
+
"types": "./dist/guardrail/*.d.ts",
|
|
92
|
+
"import": "./dist/guardrail/*.js"
|
|
93
|
+
},
|
|
54
94
|
"./testing": {
|
|
55
95
|
"types": "./dist/testing/index.d.ts",
|
|
56
96
|
"import": "./dist/testing/index.js"
|
|
57
97
|
},
|
|
98
|
+
"./testing/*": {
|
|
99
|
+
"types": "./dist/testing/*.d.ts",
|
|
100
|
+
"import": "./dist/testing/*.js"
|
|
101
|
+
},
|
|
58
102
|
"./providers": {
|
|
59
103
|
"types": "./dist/providers/index.d.ts",
|
|
60
104
|
"import": "./dist/providers/index.js"
|
|
105
|
+
},
|
|
106
|
+
"./providers/*": {
|
|
107
|
+
"types": "./dist/providers/*.d.ts",
|
|
108
|
+
"import": "./dist/providers/*.js"
|
|
109
|
+
},
|
|
110
|
+
"./approval": {
|
|
111
|
+
"types": "./dist/approval/index.d.ts",
|
|
112
|
+
"import": "./dist/approval/index.js"
|
|
113
|
+
},
|
|
114
|
+
"./approval/*": {
|
|
115
|
+
"types": "./dist/approval/*.d.ts",
|
|
116
|
+
"import": "./dist/approval/*.js"
|
|
117
|
+
},
|
|
118
|
+
"./document": {
|
|
119
|
+
"types": "./dist/document/index.d.ts",
|
|
120
|
+
"import": "./dist/document/index.js"
|
|
121
|
+
},
|
|
122
|
+
"./document/*": {
|
|
123
|
+
"types": "./dist/document/*.d.ts",
|
|
124
|
+
"import": "./dist/document/*.js"
|
|
125
|
+
},
|
|
126
|
+
"./events": {
|
|
127
|
+
"types": "./dist/events/index.d.ts",
|
|
128
|
+
"import": "./dist/events/index.js"
|
|
129
|
+
},
|
|
130
|
+
"./events/*": {
|
|
131
|
+
"types": "./dist/events/*.d.ts",
|
|
132
|
+
"import": "./dist/events/*.js"
|
|
133
|
+
},
|
|
134
|
+
"./inngest": {
|
|
135
|
+
"types": "./dist/inngest/index.d.ts",
|
|
136
|
+
"import": "./dist/inngest/index.js"
|
|
137
|
+
},
|
|
138
|
+
"./inngest/*": {
|
|
139
|
+
"types": "./dist/inngest/*.d.ts",
|
|
140
|
+
"import": "./dist/inngest/*.js"
|
|
141
|
+
},
|
|
142
|
+
"./jobs": {
|
|
143
|
+
"types": "./dist/jobs/index.d.ts",
|
|
144
|
+
"import": "./dist/jobs/index.js"
|
|
145
|
+
},
|
|
146
|
+
"./jobs/*": {
|
|
147
|
+
"types": "./dist/jobs/*.d.ts",
|
|
148
|
+
"import": "./dist/jobs/*.js"
|
|
149
|
+
},
|
|
150
|
+
"./notification": {
|
|
151
|
+
"types": "./dist/notification/index.d.ts",
|
|
152
|
+
"import": "./dist/notification/index.js"
|
|
153
|
+
},
|
|
154
|
+
"./notification/*": {
|
|
155
|
+
"types": "./dist/notification/*.d.ts",
|
|
156
|
+
"import": "./dist/notification/*.js"
|
|
157
|
+
},
|
|
158
|
+
"./realtime": {
|
|
159
|
+
"types": "./dist/realtime/index.d.ts",
|
|
160
|
+
"import": "./dist/realtime/index.js"
|
|
161
|
+
},
|
|
162
|
+
"./realtime/*": {
|
|
163
|
+
"types": "./dist/realtime/*.d.ts",
|
|
164
|
+
"import": "./dist/realtime/*.js"
|
|
165
|
+
},
|
|
166
|
+
"./search": {
|
|
167
|
+
"types": "./dist/search/index.d.ts",
|
|
168
|
+
"import": "./dist/search/index.js"
|
|
169
|
+
},
|
|
170
|
+
"./search/*": {
|
|
171
|
+
"types": "./dist/search/*.d.ts",
|
|
172
|
+
"import": "./dist/search/*.js"
|
|
173
|
+
},
|
|
174
|
+
"./webhook": {
|
|
175
|
+
"types": "./dist/webhook/index.d.ts",
|
|
176
|
+
"import": "./dist/webhook/index.js"
|
|
177
|
+
},
|
|
178
|
+
"./webhook/*": {
|
|
179
|
+
"types": "./dist/webhook/*.d.ts",
|
|
180
|
+
"import": "./dist/webhook/*.js"
|
|
61
181
|
}
|
|
62
182
|
},
|
|
63
183
|
"files": [
|
|
@@ -67,7 +187,7 @@
|
|
|
67
187
|
"ai": "^6.0.0",
|
|
68
188
|
"zod": "^3.24.0",
|
|
69
189
|
"zod-to-json-schema": "^3.24.5",
|
|
70
|
-
"@sprinterai/core": "^0.
|
|
190
|
+
"@sprinterai/core": "^0.7.1"
|
|
71
191
|
},
|
|
72
192
|
"devDependencies": {
|
|
73
193
|
"@vitest/coverage-v8": "^3.0.0",
|
|
@@ -77,7 +197,7 @@
|
|
|
77
197
|
"@sprinterai/eslint-config": "0.1.0"
|
|
78
198
|
},
|
|
79
199
|
"publishConfig": {
|
|
80
|
-
"access": "
|
|
200
|
+
"access": "public"
|
|
81
201
|
},
|
|
82
202
|
"repository": {
|
|
83
203
|
"type": "git",
|