zeitlich 0.2.16 → 0.2.17
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/README.md +75 -64
- package/dist/adapters/sandbox/virtual/index.cjs +45 -0
- package/dist/adapters/sandbox/virtual/index.cjs.map +1 -1
- package/dist/adapters/sandbox/virtual/index.d.cts +2 -2
- package/dist/adapters/sandbox/virtual/index.d.ts +2 -2
- package/dist/adapters/sandbox/virtual/index.js +43 -1
- package/dist/adapters/sandbox/virtual/index.js.map +1 -1
- package/dist/adapters/thread/google-genai/index.d.cts +1 -1
- package/dist/adapters/thread/google-genai/index.d.ts +1 -1
- package/dist/adapters/thread/langchain/index.cjs +2 -2
- package/dist/adapters/thread/langchain/index.cjs.map +1 -1
- package/dist/adapters/thread/langchain/index.d.cts +1 -1
- package/dist/adapters/thread/langchain/index.d.ts +1 -1
- package/dist/adapters/thread/langchain/index.js +2 -2
- package/dist/adapters/thread/langchain/index.js.map +1 -1
- package/dist/index.cjs +100 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +96 -8
- package/dist/index.js.map +1 -1
- package/dist/{types-BSOte_8s.d.ts → queries-BlC1I3DK.d.ts} +42 -1
- package/dist/{types-DCi2qXjN.d.cts → queries-DlJ3jE48.d.cts} +42 -1
- package/dist/{types-Drli9aCK.d.cts → types-Bh-BbfCp.d.cts} +30 -11
- package/dist/{types-XPtivmSJ.d.ts → types-NkiAxU4t.d.ts} +30 -11
- package/dist/workflow.cjs +100 -7
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +112 -38
- package/dist/workflow.d.ts +112 -38
- package/dist/workflow.js +96 -8
- package/dist/workflow.js.map +1 -1
- package/package.json +1 -1
- package/src/adapters/sandbox/virtual/index.ts +2 -0
- package/src/adapters/sandbox/virtual/queries.ts +97 -0
- package/src/adapters/thread/langchain/activities.ts +7 -5
- package/src/lib/session/session.integration.test.ts +1 -0
- package/src/lib/subagent/define.ts +34 -47
- package/src/lib/subagent/handler.ts +9 -6
- package/src/lib/subagent/index.ts +4 -1
- package/src/lib/subagent/subagent.integration.test.ts +113 -7
- package/src/lib/subagent/types.ts +40 -10
- package/src/lib/subagent/workflow.ts +114 -0
- package/src/lib/workflow.test.ts +131 -0
- package/src/lib/workflow.ts +45 -0
- package/src/workflow.ts +12 -2
|
@@ -122,4 +122,45 @@ interface VirtualSandboxContext<TCtx = unknown, TMeta = FileEntryMetadata> exten
|
|
|
122
122
|
sandbox: VirtualSandbox<TCtx, TMeta>;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
|
|
125
|
+
/**
|
|
126
|
+
* Structural constraint: accepts any `AgentStateManager<T>` whose custom
|
|
127
|
+
* state includes `fileTree: FileEntry<TMeta>[]`.
|
|
128
|
+
*/
|
|
129
|
+
interface FileTreeAccessor<TMeta> {
|
|
130
|
+
get(key: "fileTree"): FileEntry<TMeta>[];
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Check whether any file in the tree has a `metadata.mimeType` that matches
|
|
134
|
+
* the given pattern.
|
|
135
|
+
*
|
|
136
|
+
* Patterns:
|
|
137
|
+
* - Exact: `"application/pdf"`
|
|
138
|
+
* - Wildcard type: `"image/*"`
|
|
139
|
+
*
|
|
140
|
+
* Useful for conditionally enabling tools:
|
|
141
|
+
*
|
|
142
|
+
* ```ts
|
|
143
|
+
* { enabled: hasFileWithMimeType(stateManager, "image/*") }
|
|
144
|
+
* { enabled: hasFileWithMimeType(stateManager, ["image/*", "application/pdf"]) }
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
declare function hasFileWithMimeType<TMeta>(stateManager: FileTreeAccessor<TMeta>, pattern: string | string[]): boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Return all entries whose `metadata.mimeType` matches the given pattern.
|
|
150
|
+
*/
|
|
151
|
+
declare function filesWithMimeType<TMeta>(stateManager: FileTreeAccessor<TMeta>, pattern: string): FileEntry<TMeta>[];
|
|
152
|
+
/**
|
|
153
|
+
* Check whether the tree contains a directory whose name matches the given
|
|
154
|
+
* pattern. Directories are inferred from file paths.
|
|
155
|
+
*
|
|
156
|
+
* Patterns:
|
|
157
|
+
* - Exact: `"src"`
|
|
158
|
+
* - Glob with `*` wildcard: `"test*"`, `"*.generated"`
|
|
159
|
+
*
|
|
160
|
+
* ```ts
|
|
161
|
+
* { enabled: hasDirectory(stateManager, "test*") }
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
declare function hasDirectory<TMeta>(stateManager: FileTreeAccessor<TMeta>, pattern: string): boolean;
|
|
165
|
+
|
|
166
|
+
export { type FileEntryMetadata as F, type TreeMutation as T, type VirtualSandboxCreateOptions as V, type FileResolver as a, type VirtualSandboxContext as b, type FileEntry as c, type VirtualSandbox as d, type FileTreeAccessor as e, type VirtualFileTree as f, VirtualSandboxFileSystem as g, type VirtualSandboxState as h, filesWithMimeType as i, hasDirectory as j, hasFileWithMimeType as k };
|
|
@@ -122,4 +122,45 @@ interface VirtualSandboxContext<TCtx = unknown, TMeta = FileEntryMetadata> exten
|
|
|
122
122
|
sandbox: VirtualSandbox<TCtx, TMeta>;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
|
|
125
|
+
/**
|
|
126
|
+
* Structural constraint: accepts any `AgentStateManager<T>` whose custom
|
|
127
|
+
* state includes `fileTree: FileEntry<TMeta>[]`.
|
|
128
|
+
*/
|
|
129
|
+
interface FileTreeAccessor<TMeta> {
|
|
130
|
+
get(key: "fileTree"): FileEntry<TMeta>[];
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Check whether any file in the tree has a `metadata.mimeType` that matches
|
|
134
|
+
* the given pattern.
|
|
135
|
+
*
|
|
136
|
+
* Patterns:
|
|
137
|
+
* - Exact: `"application/pdf"`
|
|
138
|
+
* - Wildcard type: `"image/*"`
|
|
139
|
+
*
|
|
140
|
+
* Useful for conditionally enabling tools:
|
|
141
|
+
*
|
|
142
|
+
* ```ts
|
|
143
|
+
* { enabled: hasFileWithMimeType(stateManager, "image/*") }
|
|
144
|
+
* { enabled: hasFileWithMimeType(stateManager, ["image/*", "application/pdf"]) }
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
declare function hasFileWithMimeType<TMeta>(stateManager: FileTreeAccessor<TMeta>, pattern: string | string[]): boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Return all entries whose `metadata.mimeType` matches the given pattern.
|
|
150
|
+
*/
|
|
151
|
+
declare function filesWithMimeType<TMeta>(stateManager: FileTreeAccessor<TMeta>, pattern: string): FileEntry<TMeta>[];
|
|
152
|
+
/**
|
|
153
|
+
* Check whether the tree contains a directory whose name matches the given
|
|
154
|
+
* pattern. Directories are inferred from file paths.
|
|
155
|
+
*
|
|
156
|
+
* Patterns:
|
|
157
|
+
* - Exact: `"src"`
|
|
158
|
+
* - Glob with `*` wildcard: `"test*"`, `"*.generated"`
|
|
159
|
+
*
|
|
160
|
+
* ```ts
|
|
161
|
+
* { enabled: hasDirectory(stateManager, "test*") }
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
declare function hasDirectory<TMeta>(stateManager: FileTreeAccessor<TMeta>, pattern: string): boolean;
|
|
165
|
+
|
|
166
|
+
export { type FileEntryMetadata as F, type TreeMutation as T, type VirtualSandboxCreateOptions as V, type FileResolver as a, type VirtualSandboxContext as b, type FileEntry as c, type VirtualSandbox as d, type FileTreeAccessor as e, type VirtualFileTree as f, VirtualSandboxFileSystem as g, type VirtualSandboxState as h, filesWithMimeType as i, hasDirectory as j, hasFileWithMimeType as k };
|
|
@@ -73,7 +73,26 @@ interface Hooks<T extends ToolMap, TResult = unknown> extends ToolRouterHooks<T,
|
|
|
73
73
|
type SubagentHandlerResponse<TResult = null> = ToolHandlerResponse<TResult> & {
|
|
74
74
|
threadId: string;
|
|
75
75
|
};
|
|
76
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Raw workflow input fields passed from parent to child workflow.
|
|
78
|
+
* `defineSubagentWorkflow` maps this into `SubagentSessionInput`.
|
|
79
|
+
*/
|
|
80
|
+
interface SubagentWorkflowInput {
|
|
81
|
+
/** Thread ID from parent for continuation */
|
|
82
|
+
previousThreadId?: string;
|
|
83
|
+
/** Sandbox ID inherited from parent */
|
|
84
|
+
sandboxId?: string;
|
|
85
|
+
}
|
|
86
|
+
type SubagentWorkflow<TResult extends z.ZodType = z.ZodType> = (prompt: string, workflowInput: SubagentWorkflowInput, context?: Record<string, unknown>) => Promise<SubagentHandlerResponse<z.infer<TResult> | null>>;
|
|
87
|
+
/**
|
|
88
|
+
* A subagent workflow with embedded metadata (name, description, resultSchema).
|
|
89
|
+
* Created by `defineSubagentWorkflow` — pass directly to `defineSubagent`.
|
|
90
|
+
*/
|
|
91
|
+
type SubagentDefinition<TResult extends z.ZodType = z.ZodType, TContext extends Record<string, unknown> = Record<string, unknown>> = ((prompt: string, workflowInput: SubagentWorkflowInput, context?: TContext) => Promise<SubagentHandlerResponse<z.infer<TResult> | null>>) & {
|
|
92
|
+
readonly agentName: string;
|
|
93
|
+
readonly description: string;
|
|
94
|
+
readonly resultSchema?: TResult;
|
|
95
|
+
};
|
|
77
96
|
/**
|
|
78
97
|
* Configuration for a subagent that can be spawned by the parent workflow.
|
|
79
98
|
*
|
|
@@ -133,16 +152,16 @@ interface SubagentHooks<TArgs = unknown, TResult = unknown> {
|
|
|
133
152
|
}) => PostToolUseFailureHookResult | Promise<PostToolUseFailureHookResult>;
|
|
134
153
|
}
|
|
135
154
|
/**
|
|
136
|
-
*
|
|
155
|
+
* Session config fields passed from parent to child workflow.
|
|
137
156
|
*/
|
|
138
|
-
interface
|
|
139
|
-
/**
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
|
|
145
|
-
/** Sandbox ID inherited from the parent agent
|
|
157
|
+
interface SubagentSessionInput {
|
|
158
|
+
/** Agent name — spread directly into `createSession` */
|
|
159
|
+
agentName: string;
|
|
160
|
+
/** Thread ID to continue from */
|
|
161
|
+
threadId?: string;
|
|
162
|
+
/** Whether to continue an existing thread */
|
|
163
|
+
continueThread?: boolean;
|
|
164
|
+
/** Sandbox ID inherited from the parent agent */
|
|
146
165
|
sandboxId?: string;
|
|
147
166
|
}
|
|
148
167
|
|
|
@@ -388,4 +407,4 @@ interface ZeitlichSession<M = unknown> {
|
|
|
388
407
|
}>;
|
|
389
408
|
}
|
|
390
409
|
|
|
391
|
-
export type { AgentResponse as A, Hooks as H, JsonPrimitive as J, ModelInvoker as M, PostHumanMessageAppendHook as P, RunAgentActivity as R, SkillProvider as S, ThreadOps as T, ZeitlichSession as Z, ModelInvokerConfig as a, SkillMetadata as b, Skill as c, AgentState as d, AgentStateManager as e, JsonSerializable as f, JsonValue as g, PostHumanMessageAppendHookContext as h, PreHumanMessageAppendHook as i, PreHumanMessageAppendHookContext as j, SessionConfig as k, SessionEndHook as l, SessionEndHookContext as m, SessionStartHook as n, SessionStartHookContext as o, SubagentConfig as p,
|
|
410
|
+
export type { AgentResponse as A, Hooks as H, JsonPrimitive as J, ModelInvoker as M, PostHumanMessageAppendHook as P, RunAgentActivity as R, SkillProvider as S, ThreadOps as T, ZeitlichSession as Z, ModelInvokerConfig as a, SkillMetadata as b, Skill as c, AgentState as d, AgentStateManager as e, JsonSerializable as f, JsonValue as g, PostHumanMessageAppendHookContext as h, PreHumanMessageAppendHook as i, PreHumanMessageAppendHookContext as j, SessionConfig as k, SessionEndHook as l, SessionEndHookContext as m, SessionStartHook as n, SessionStartHookContext as o, SubagentConfig as p, SubagentDefinition as q, SubagentHandlerResponse as r, SubagentHooks as s, SubagentSessionInput as t, SubagentWorkflow as u, SubagentWorkflowInput as v };
|
|
@@ -73,7 +73,26 @@ interface Hooks<T extends ToolMap, TResult = unknown> extends ToolRouterHooks<T,
|
|
|
73
73
|
type SubagentHandlerResponse<TResult = null> = ToolHandlerResponse<TResult> & {
|
|
74
74
|
threadId: string;
|
|
75
75
|
};
|
|
76
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Raw workflow input fields passed from parent to child workflow.
|
|
78
|
+
* `defineSubagentWorkflow` maps this into `SubagentSessionInput`.
|
|
79
|
+
*/
|
|
80
|
+
interface SubagentWorkflowInput {
|
|
81
|
+
/** Thread ID from parent for continuation */
|
|
82
|
+
previousThreadId?: string;
|
|
83
|
+
/** Sandbox ID inherited from parent */
|
|
84
|
+
sandboxId?: string;
|
|
85
|
+
}
|
|
86
|
+
type SubagentWorkflow<TResult extends z.ZodType = z.ZodType> = (prompt: string, workflowInput: SubagentWorkflowInput, context?: Record<string, unknown>) => Promise<SubagentHandlerResponse<z.infer<TResult> | null>>;
|
|
87
|
+
/**
|
|
88
|
+
* A subagent workflow with embedded metadata (name, description, resultSchema).
|
|
89
|
+
* Created by `defineSubagentWorkflow` — pass directly to `defineSubagent`.
|
|
90
|
+
*/
|
|
91
|
+
type SubagentDefinition<TResult extends z.ZodType = z.ZodType, TContext extends Record<string, unknown> = Record<string, unknown>> = ((prompt: string, workflowInput: SubagentWorkflowInput, context?: TContext) => Promise<SubagentHandlerResponse<z.infer<TResult> | null>>) & {
|
|
92
|
+
readonly agentName: string;
|
|
93
|
+
readonly description: string;
|
|
94
|
+
readonly resultSchema?: TResult;
|
|
95
|
+
};
|
|
77
96
|
/**
|
|
78
97
|
* Configuration for a subagent that can be spawned by the parent workflow.
|
|
79
98
|
*
|
|
@@ -133,16 +152,16 @@ interface SubagentHooks<TArgs = unknown, TResult = unknown> {
|
|
|
133
152
|
}) => PostToolUseFailureHookResult | Promise<PostToolUseFailureHookResult>;
|
|
134
153
|
}
|
|
135
154
|
/**
|
|
136
|
-
*
|
|
155
|
+
* Session config fields passed from parent to child workflow.
|
|
137
156
|
*/
|
|
138
|
-
interface
|
|
139
|
-
/**
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
|
|
145
|
-
/** Sandbox ID inherited from the parent agent
|
|
157
|
+
interface SubagentSessionInput {
|
|
158
|
+
/** Agent name — spread directly into `createSession` */
|
|
159
|
+
agentName: string;
|
|
160
|
+
/** Thread ID to continue from */
|
|
161
|
+
threadId?: string;
|
|
162
|
+
/** Whether to continue an existing thread */
|
|
163
|
+
continueThread?: boolean;
|
|
164
|
+
/** Sandbox ID inherited from the parent agent */
|
|
146
165
|
sandboxId?: string;
|
|
147
166
|
}
|
|
148
167
|
|
|
@@ -388,4 +407,4 @@ interface ZeitlichSession<M = unknown> {
|
|
|
388
407
|
}>;
|
|
389
408
|
}
|
|
390
409
|
|
|
391
|
-
export type { AgentResponse as A, Hooks as H, JsonPrimitive as J, ModelInvoker as M, PostHumanMessageAppendHook as P, RunAgentActivity as R, SkillProvider as S, ThreadOps as T, ZeitlichSession as Z, ModelInvokerConfig as a, SkillMetadata as b, Skill as c, AgentState as d, AgentStateManager as e, JsonSerializable as f, JsonValue as g, PostHumanMessageAppendHookContext as h, PreHumanMessageAppendHook as i, PreHumanMessageAppendHookContext as j, SessionConfig as k, SessionEndHook as l, SessionEndHookContext as m, SessionStartHook as n, SessionStartHookContext as o, SubagentConfig as p,
|
|
410
|
+
export type { AgentResponse as A, Hooks as H, JsonPrimitive as J, ModelInvoker as M, PostHumanMessageAppendHook as P, RunAgentActivity as R, SkillProvider as S, ThreadOps as T, ZeitlichSession as Z, ModelInvokerConfig as a, SkillMetadata as b, Skill as c, AgentState as d, AgentStateManager as e, JsonSerializable as f, JsonValue as g, PostHumanMessageAppendHookContext as h, PreHumanMessageAppendHook as i, PreHumanMessageAppendHookContext as j, SessionConfig as k, SessionEndHook as l, SessionEndHookContext as m, SessionStartHook as n, SessionStartHookContext as o, SubagentConfig as p, SubagentDefinition as q, SubagentHandlerResponse as r, SubagentHooks as s, SubagentSessionInput as t, SubagentWorkflow as u, SubagentWorkflowInput as v };
|
package/dist/workflow.cjs
CHANGED
|
@@ -336,15 +336,15 @@ function createSubagentHandler(subagents) {
|
|
|
336
336
|
const childWorkflowId = `${args.subagent}-${getShortId()}`;
|
|
337
337
|
const { sandboxId: parentSandboxId } = context;
|
|
338
338
|
const inheritSandbox = config.sandbox !== "own" && !!parentSandboxId;
|
|
339
|
-
const
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
339
|
+
const workflowInput = {
|
|
340
|
+
...args.threadId && args.threadId !== null && config.allowThreadContinuation && {
|
|
341
|
+
previousThreadId: args.threadId
|
|
342
|
+
},
|
|
343
343
|
...inheritSandbox && { sandboxId: parentSandboxId }
|
|
344
344
|
};
|
|
345
345
|
const childOpts = {
|
|
346
346
|
workflowId: childWorkflowId,
|
|
347
|
-
args: [
|
|
347
|
+
args: config.context === void 0 ? [args.prompt, workflowInput] : [args.prompt, workflowInput, config.context],
|
|
348
348
|
taskQueue: config.taskQueue ?? parentTaskQueue
|
|
349
349
|
};
|
|
350
350
|
const {
|
|
@@ -698,6 +698,20 @@ function proxySandboxOps(options) {
|
|
|
698
698
|
);
|
|
699
699
|
}
|
|
700
700
|
|
|
701
|
+
// src/lib/workflow.ts
|
|
702
|
+
function defineWorkflow(fn) {
|
|
703
|
+
return async (input, workflowInput = {}) => {
|
|
704
|
+
const sessionInput = {
|
|
705
|
+
...workflowInput.previousThreadId && {
|
|
706
|
+
threadId: workflowInput.previousThreadId,
|
|
707
|
+
continueThread: true
|
|
708
|
+
},
|
|
709
|
+
...workflowInput.sandboxId && { sandboxId: workflowInput.sandboxId }
|
|
710
|
+
};
|
|
711
|
+
return fn(input, sessionInput);
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
|
|
701
715
|
// src/lib/types.ts
|
|
702
716
|
function isTerminalStatus(status) {
|
|
703
717
|
return status === "COMPLETED" || status === "FAILED" || status === "CANCELLED";
|
|
@@ -860,8 +874,40 @@ function createAgentStateManager({
|
|
|
860
874
|
}
|
|
861
875
|
|
|
862
876
|
// src/lib/subagent/define.ts
|
|
863
|
-
function defineSubagent(
|
|
864
|
-
return
|
|
877
|
+
function defineSubagent(definition, overrides) {
|
|
878
|
+
return {
|
|
879
|
+
agentName: definition.agentName,
|
|
880
|
+
description: definition.description,
|
|
881
|
+
workflow: definition,
|
|
882
|
+
...definition.resultSchema !== void 0 && {
|
|
883
|
+
resultSchema: definition.resultSchema
|
|
884
|
+
},
|
|
885
|
+
...overrides
|
|
886
|
+
};
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
// src/lib/subagent/workflow.ts
|
|
890
|
+
function defineSubagentWorkflow(config, fn) {
|
|
891
|
+
const workflow = async (prompt, workflowInput, context) => {
|
|
892
|
+
const sessionInput = {
|
|
893
|
+
agentName: config.name,
|
|
894
|
+
...workflowInput.previousThreadId && {
|
|
895
|
+
threadId: workflowInput.previousThreadId,
|
|
896
|
+
continueThread: true
|
|
897
|
+
},
|
|
898
|
+
...workflowInput.sandboxId && { sandboxId: workflowInput.sandboxId }
|
|
899
|
+
};
|
|
900
|
+
return fn(prompt, sessionInput, context ?? {});
|
|
901
|
+
};
|
|
902
|
+
Object.defineProperty(workflow, "name", { value: config.name });
|
|
903
|
+
return Object.assign(workflow, {
|
|
904
|
+
agentName: config.name,
|
|
905
|
+
description: config.description,
|
|
906
|
+
...config.resultSchema !== void 0 && {
|
|
907
|
+
resultSchema: config.resultSchema
|
|
908
|
+
}
|
|
909
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
910
|
+
});
|
|
865
911
|
}
|
|
866
912
|
var SandboxNotSupportedError = class extends common.ApplicationFailure {
|
|
867
913
|
constructor(operation) {
|
|
@@ -948,6 +994,48 @@ function formatVirtualFileTree(entries, opts = {}) {
|
|
|
948
994
|
return "/" + printNode(root, "", sort);
|
|
949
995
|
}
|
|
950
996
|
|
|
997
|
+
// src/adapters/sandbox/virtual/queries.ts
|
|
998
|
+
function hasFileWithMimeType(stateManager, pattern) {
|
|
999
|
+
const tree = stateManager.get("fileTree");
|
|
1000
|
+
const matchers = (Array.isArray(pattern) ? pattern : [pattern]).map(buildMatcher);
|
|
1001
|
+
return tree.some((entry) => {
|
|
1002
|
+
const meta = entry.metadata;
|
|
1003
|
+
const mime = meta?.mimeType;
|
|
1004
|
+
return typeof mime === "string" && matchers.some((m) => m(mime));
|
|
1005
|
+
});
|
|
1006
|
+
}
|
|
1007
|
+
function filesWithMimeType(stateManager, pattern) {
|
|
1008
|
+
const tree = stateManager.get("fileTree");
|
|
1009
|
+
const match = buildMatcher(pattern);
|
|
1010
|
+
return tree.filter((entry) => {
|
|
1011
|
+
const meta = entry.metadata;
|
|
1012
|
+
const mime = meta?.mimeType;
|
|
1013
|
+
return typeof mime === "string" && match(mime);
|
|
1014
|
+
});
|
|
1015
|
+
}
|
|
1016
|
+
function hasDirectory(stateManager, pattern) {
|
|
1017
|
+
const tree = stateManager.get("fileTree");
|
|
1018
|
+
const match = buildGlobMatcher(pattern);
|
|
1019
|
+
return tree.some((entry) => {
|
|
1020
|
+
const segments = entry.path.split("/").filter(Boolean);
|
|
1021
|
+
return segments.slice(0, -1).some(match);
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
function buildMatcher(pattern) {
|
|
1025
|
+
if (pattern.endsWith("/*")) {
|
|
1026
|
+
const prefix = pattern.slice(0, -1);
|
|
1027
|
+
return (v) => v.startsWith(prefix);
|
|
1028
|
+
}
|
|
1029
|
+
return (v) => v === pattern;
|
|
1030
|
+
}
|
|
1031
|
+
function buildGlobMatcher(pattern) {
|
|
1032
|
+
if (!pattern.includes("*")) return (v) => v === pattern;
|
|
1033
|
+
const re = new RegExp(
|
|
1034
|
+
"^" + pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*") + "$"
|
|
1035
|
+
);
|
|
1036
|
+
return (v) => re.test(v);
|
|
1037
|
+
}
|
|
1038
|
+
|
|
951
1039
|
// src/lib/skills/parse.ts
|
|
952
1040
|
function parseSkillFile(raw) {
|
|
953
1041
|
const trimmed = raw.replace(/^\uFEFF/, "");
|
|
@@ -1387,12 +1475,17 @@ exports.createTaskListHandler = createTaskListHandler;
|
|
|
1387
1475
|
exports.createTaskUpdateHandler = createTaskUpdateHandler;
|
|
1388
1476
|
exports.createToolRouter = createToolRouter;
|
|
1389
1477
|
exports.defineSubagent = defineSubagent;
|
|
1478
|
+
exports.defineSubagentWorkflow = defineSubagentWorkflow;
|
|
1390
1479
|
exports.defineTool = defineTool;
|
|
1480
|
+
exports.defineWorkflow = defineWorkflow;
|
|
1391
1481
|
exports.editTool = editTool;
|
|
1482
|
+
exports.filesWithMimeType = filesWithMimeType;
|
|
1392
1483
|
exports.formatVirtualFileTree = formatVirtualFileTree;
|
|
1393
1484
|
exports.getShortId = getShortId;
|
|
1394
1485
|
exports.globTool = globTool;
|
|
1395
1486
|
exports.grepTool = grepTool;
|
|
1487
|
+
exports.hasDirectory = hasDirectory;
|
|
1488
|
+
exports.hasFileWithMimeType = hasFileWithMimeType;
|
|
1396
1489
|
exports.hasNoOtherToolCalls = hasNoOtherToolCalls;
|
|
1397
1490
|
exports.isTerminalStatus = isTerminalStatus;
|
|
1398
1491
|
exports.parseSkillFile = parseSkillFile;
|