@levelcode/sdk 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/src/actions.d.ts +176 -0
- package/dist/common/src/analytics-core.d.ts +52 -0
- package/dist/common/src/analytics.d.ts +9 -0
- package/dist/common/src/browser-actions.d.ts +1200 -0
- package/dist/common/src/constants/agents.d.ts +47 -0
- package/dist/common/src/constants/analytics-events.d.ts +107 -0
- package/dist/common/src/constants/byok.d.ts +2 -0
- package/dist/common/src/constants/claude-oauth.d.ts +36 -0
- package/dist/common/src/constants/index.d.ts +4 -0
- package/dist/common/src/constants/knowledge.d.ts +21 -0
- package/dist/common/src/constants/limits.d.ts +14 -0
- package/dist/common/src/constants/model-config.d.ts +117 -0
- package/dist/common/src/constants/paths.d.ts +23 -0
- package/dist/common/src/constants/skills.d.ts +42 -0
- package/dist/common/src/constants/ui.d.ts +14 -0
- package/dist/common/src/env-ci.d.ts +22 -0
- package/dist/common/src/env-process.d.ts +28 -0
- package/dist/common/src/env-schema.d.ts +24 -0
- package/dist/common/src/env.d.ts +16 -0
- package/dist/common/src/mcp/client.d.ts +6 -0
- package/dist/common/src/old-constants.d.ts +10 -0
- package/dist/common/src/project-file-tree.d.ts +27 -0
- package/dist/common/src/templates/agent-validation.d.ts +48 -0
- package/dist/common/src/templates/initial-agents-dir/types/agent-definition.d.ts +296 -0
- package/dist/common/src/templates/initial-agents-dir/types/tools.d.ts +308 -0
- package/dist/common/src/templates/initial-agents-dir/types/util-types.d.ts +128 -0
- package/dist/common/src/testing/errors.d.ts +14 -0
- package/dist/common/src/testing/mock-modules.d.ts +11 -0
- package/dist/common/src/testing/mock-types.d.ts +97 -0
- package/dist/common/src/testing/mocks/analytics.d.ts +182 -0
- package/dist/common/src/testing/mocks/child-process.d.ts +29 -0
- package/dist/common/src/testing/mocks/crypto.d.ts +159 -0
- package/dist/common/src/testing/mocks/database.d.ts +197 -0
- package/dist/common/src/testing/mocks/fetch.d.ts +35 -0
- package/dist/common/src/testing/mocks/filesystem.d.ts +31 -0
- package/dist/common/src/testing/mocks/index.d.ts +25 -0
- package/dist/common/src/testing/mocks/logger.d.ts +35 -0
- package/dist/common/src/testing/mocks/stream.d.ts +203 -0
- package/dist/common/src/testing/mocks/timers.d.ts +27 -0
- package/dist/common/src/testing/mocks/tree-sitter.d.ts +58 -0
- package/dist/common/src/testing-env-process.d.ts +7 -0
- package/dist/common/src/tools/constants.d.ts +17 -0
- package/dist/common/src/tools/list.d.ts +1140 -0
- package/dist/common/src/tools/params/tool/add-message.d.ts +19 -0
- package/dist/common/src/tools/params/tool/add-subgoal.d.ts +26 -0
- package/dist/common/src/tools/params/tool/ask-user.d.ts +59 -0
- package/dist/common/src/tools/params/tool/browser-logs.d.ts +127 -0
- package/dist/common/src/tools/params/tool/code-search.d.ts +30 -0
- package/dist/common/src/tools/params/tool/create-plan.d.ts +30 -0
- package/dist/common/src/tools/params/tool/end-turn.d.ts +13 -0
- package/dist/common/src/tools/params/tool/find-files.d.ts +31 -0
- package/dist/common/src/tools/params/tool/glob.d.ts +26 -0
- package/dist/common/src/tools/params/tool/list-directory.d.ts +25 -0
- package/dist/common/src/tools/params/tool/lookup-agent-info.d.ts +13 -0
- package/dist/common/src/tools/params/tool/propose-str-replace.d.ts +40 -0
- package/dist/common/src/tools/params/tool/propose-write-file.d.ts +29 -0
- package/dist/common/src/tools/params/tool/read-docs.d.ts +19 -0
- package/dist/common/src/tools/params/tool/read-files.d.ts +35 -0
- package/dist/common/src/tools/params/tool/read-subtree.d.ts +40 -0
- package/dist/common/src/tools/params/tool/run-file-change-hooks.d.ts +63 -0
- package/dist/common/src/tools/params/tool/run-terminal-command.d.ts +88 -0
- package/dist/common/src/tools/params/tool/send-message.d.ts +26 -0
- package/dist/common/src/tools/params/tool/set-messages.d.ts +15 -0
- package/dist/common/src/tools/params/tool/set-output.d.ts +15 -0
- package/dist/common/src/tools/params/tool/skill.d.ts +28 -0
- package/dist/common/src/tools/params/tool/spawn-agent-inline.d.ts +17 -0
- package/dist/common/src/tools/params/tool/spawn-agents.d.ts +26 -0
- package/dist/common/src/tools/params/tool/str-replace.d.ts +43 -0
- package/dist/common/src/tools/params/tool/suggest-followups.d.ts +26 -0
- package/dist/common/src/tools/params/tool/task-completed.d.ts +13 -0
- package/dist/common/src/tools/params/tool/task-create.d.ts +18 -0
- package/dist/common/src/tools/params/tool/task-get.d.ts +15 -0
- package/dist/common/src/tools/params/tool/task-list.d.ts +13 -0
- package/dist/common/src/tools/params/tool/task-update.d.ts +23 -0
- package/dist/common/src/tools/params/tool/team-create.d.ts +17 -0
- package/dist/common/src/tools/params/tool/team-delete.d.ts +13 -0
- package/dist/common/src/tools/params/tool/think-deeply.d.ts +15 -0
- package/dist/common/src/tools/params/tool/update-subgoal.d.ts +25 -0
- package/dist/common/src/tools/params/tool/web-search.d.ts +25 -0
- package/dist/common/src/tools/params/tool/write-file.d.ts +31 -0
- package/dist/common/src/tools/params/tool/write-todos.d.ts +18 -0
- package/dist/common/src/tools/params/utils.d.ts +35 -0
- package/dist/common/src/tools/utils.d.ts +4 -0
- package/dist/common/src/types/agent-template.d.ts +156 -0
- package/dist/common/src/types/contracts/agent-runtime.d.ts +36 -0
- package/dist/common/src/types/contracts/analytics.d.ts +8 -0
- package/dist/common/src/types/contracts/billing.d.ts +40 -0
- package/dist/common/src/types/contracts/client.d.ts +45 -0
- package/dist/common/src/types/contracts/database.d.ts +80 -0
- package/dist/common/src/types/contracts/env.d.ts +150 -0
- package/dist/common/src/types/contracts/llm.d.ts +102 -0
- package/dist/common/src/types/contracts/logger.d.ts +8 -0
- package/dist/common/src/types/dynamic-agent-template.d.ts +227 -0
- package/dist/common/src/types/filesystem.d.ts +6 -0
- package/dist/common/src/types/function-params.d.ts +15 -0
- package/dist/common/src/types/grant.d.ts +2 -0
- package/dist/common/src/types/json.d.ts +9 -0
- package/dist/common/src/types/mcp.d.ts +31 -0
- package/dist/common/src/types/messages/content-part.d.ts +46 -0
- package/dist/common/src/types/messages/data-content.d.ts +3 -0
- package/dist/common/src/types/messages/levelcode-message.d.ts +37 -0
- package/dist/common/src/types/messages/provider-metadata.d.ts +3 -0
- package/dist/common/src/types/print-mode.d.ts +155 -0
- package/dist/common/src/types/session-state.d.ts +94 -0
- package/dist/common/src/types/skill.d.ts +31 -0
- package/dist/common/src/types/source.d.ts +8 -0
- package/dist/common/src/types/spawn.d.ts +8 -0
- package/dist/common/src/types/team-config.d.ts +39 -0
- package/dist/common/src/types/team-protocol.d.ts +64 -0
- package/dist/common/src/util/agent-id-parsing.d.ts +22 -0
- package/dist/common/src/util/agent-name-normalization.d.ts +12 -0
- package/dist/common/src/util/array.d.ts +6 -0
- package/dist/common/src/util/credentials.d.ts +11 -0
- package/dist/common/src/util/error.d.ts +128 -0
- package/dist/common/src/util/file.d.ts +133 -0
- package/dist/common/src/util/format-code-search.d.ts +16 -0
- package/dist/common/src/util/lru-cache.d.ts +30 -0
- package/dist/common/src/util/messages.d.ts +46 -0
- package/dist/common/src/util/model-utils.d.ts +8 -0
- package/dist/common/src/util/object.d.ts +22 -0
- package/dist/common/src/util/promise.d.ts +16 -0
- package/dist/common/src/util/random.d.ts +1 -0
- package/dist/common/src/util/skills.d.ts +5 -0
- package/dist/common/src/util/stop-sequence.d.ts +14 -0
- package/dist/common/src/util/string.d.ts +82 -0
- package/dist/common/src/util/xml.d.ts +12 -0
- package/dist/common/src/util/zod-schema.d.ts +5 -0
- package/dist/common/src/utils/team-fs.d.ts +17 -0
- package/dist/index.cjs +1958 -917
- package/dist/index.cjs.map +25 -10
- package/dist/index.mjs +2392 -1351
- package/dist/index.mjs.map +25 -10
- package/dist/packages/agent-runtime/src/constants.d.ts +1 -0
- package/dist/packages/agent-runtime/src/fast-rewrite.d.ts +45 -0
- package/dist/packages/agent-runtime/src/find-files/request-files-prompt.d.ts +71 -0
- package/dist/packages/agent-runtime/src/generate-diffs-prompt.d.ts +53 -0
- package/dist/packages/agent-runtime/src/get-file-reading-updates.d.ts +8 -0
- package/dist/packages/agent-runtime/src/llm-api/claude.d.ts +5 -0
- package/dist/packages/agent-runtime/src/llm-api/context7-api.d.ts +55 -0
- package/dist/packages/agent-runtime/src/llm-api/gemini-with-fallbacks.d.ts +40 -0
- package/dist/packages/agent-runtime/src/llm-api/levelcode-web-api.d.ts +49 -0
- package/dist/packages/agent-runtime/src/llm-api/relace-api.d.ts +16 -0
- package/dist/packages/agent-runtime/src/main-prompt.d.ts +29 -0
- package/dist/packages/agent-runtime/src/mcp-constants.d.ts +12 -0
- package/dist/packages/agent-runtime/src/mcp.d.ts +10 -0
- package/dist/packages/agent-runtime/src/process-file-block.d.ts +56 -0
- package/dist/packages/agent-runtime/src/process-str-replace.d.ts +21 -0
- package/dist/packages/agent-runtime/src/prompt-agent-stream.d.ts +28 -0
- package/dist/packages/agent-runtime/src/run-agent-step.d.ts +73 -0
- package/dist/packages/agent-runtime/src/run-programmatic-step.d.ts +40 -0
- package/dist/packages/agent-runtime/src/system-prompt/prompts.d.ts +19 -0
- package/dist/packages/agent-runtime/src/system-prompt/search-system-prompt.d.ts +14 -0
- package/dist/packages/agent-runtime/src/system-prompt/truncate-file-tree.d.ts +13 -0
- package/dist/packages/agent-runtime/src/templates/agent-registry.d.ts +35 -0
- package/dist/packages/agent-runtime/src/templates/prompts.d.ts +35 -0
- package/dist/packages/agent-runtime/src/templates/strings.d.ts +32 -0
- package/dist/packages/agent-runtime/src/templates/types.d.ts +13 -0
- package/dist/packages/agent-runtime/src/tool-stream-parser.d.ts +31 -0
- package/dist/packages/agent-runtime/src/tools/handlers/handler-function-type.d.ts +51 -0
- package/dist/packages/agent-runtime/src/tools/handlers/list.d.ts +347 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/add-message.d.ts +9 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/add-subgoal.d.ts +9 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/ask-user.d.ts +10 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/browser-logs.d.ts +8 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/code-search.d.ts +8 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/create-plan.d.ts +13 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/end-turn.d.ts +7 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/find-files.d.ts +27 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/glob.d.ts +10 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/list-directory.d.ts +10 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/lookup-agent-info.d.ts +14 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/propose-str-replace.d.ts +15 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/propose-write-file.d.ts +7 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/proposed-content-store.d.ts +27 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/read-docs.d.ts +21 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/read-files.d.ts +13 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/read-subtree.d.ts +13 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/run-file-change-hooks.d.ts +10 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/run-terminal-command.d.ts +10 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/send-message.d.ts +10 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/set-messages.d.ts +9 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/set-output.d.ts +18 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/skill.d.ts +11 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/spawn-agent-inline.d.ts +29 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/spawn-agent-utils.d.ts +100 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/spawn-agents.d.ts +35 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/str-replace.d.ts +16 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/suggest-followups.d.ts +9 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/task-completed.d.ts +7 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/task-create.d.ts +9 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/task-get.d.ts +9 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/task-list.d.ts +9 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/task-update.d.ts +9 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/team-create.d.ts +10 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/team-delete.d.ts +10 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/think-deeply.d.ts +9 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/update-subgoal.d.ts +11 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/web-search.d.ts +22 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/write-file.d.ts +49 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/write-todos.d.ts +9 -0
- package/dist/packages/agent-runtime/src/tools/prompts.d.ts +31 -0
- package/dist/packages/agent-runtime/src/tools/stream-parser.d.ts +33 -0
- package/dist/packages/agent-runtime/src/tools/tool-executor.d.ts +87 -0
- package/dist/packages/agent-runtime/src/util/agent-output.d.ts +3 -0
- package/dist/packages/agent-runtime/src/util/messages.d.ts +68 -0
- package/dist/packages/agent-runtime/src/util/parse-tool-calls-from-text.d.ts +38 -0
- package/dist/packages/agent-runtime/src/util/render-read-files-result.d.ts +15 -0
- package/dist/packages/agent-runtime/src/util/simplify-tool-results.d.ts +7 -0
- package/dist/packages/agent-runtime/src/util/stream-xml-parser.d.ts +34 -0
- package/dist/packages/agent-runtime/src/util/token-counter.d.ts +3 -0
- package/dist/packages/code-map/src/index.d.ts +3 -0
- package/dist/packages/code-map/src/init-node.d.ts +4 -0
- package/dist/packages/code-map/src/languages.d.ts +36 -0
- package/dist/packages/code-map/src/parse.d.ts +21 -0
- package/dist/packages/code-map/src/types.d.ts +8 -0
- package/dist/packages/code-map/src/utils.d.ts +1 -0
- package/dist/sdk/src/__tests__/client.test.d.ts +1 -0
- package/dist/sdk/src/__tests__/code-search.test.d.ts +1 -0
- package/dist/sdk/src/__tests__/credentials.test.d.ts +1 -0
- package/dist/sdk/src/__tests__/database.test.d.ts +1 -0
- package/dist/sdk/src/__tests__/env.test.d.ts +1 -0
- package/dist/sdk/src/__tests__/error-utils.test.d.ts +1 -0
- package/dist/sdk/src/__tests__/initial-session-state.test.d.ts +1 -0
- package/dist/sdk/src/__tests__/knowledge-file-selection.test.d.ts +1 -0
- package/dist/sdk/src/__tests__/load-agents.test.d.ts +1 -0
- package/dist/sdk/src/__tests__/load-mcp-config.test.d.ts +1 -0
- package/dist/sdk/src/__tests__/model-provider.test.d.ts +1 -0
- package/dist/sdk/src/__tests__/read-files.test.d.ts +1 -0
- package/dist/sdk/src/__tests__/run-cancellation.test.d.ts +1 -0
- package/dist/sdk/src/__tests__/run-file-filter.test.d.ts +1 -0
- package/dist/sdk/src/__tests__/run-handle-event.test.d.ts +1 -0
- package/dist/sdk/src/__tests__/run.integration.test.d.ts +1 -0
- package/dist/sdk/src/__tests__/user-knowledge-files.test.d.ts +1 -0
- package/dist/sdk/src/__tests__/validate-agents.test.d.ts +1 -0
- package/dist/sdk/src/agents/load-agents.d.ts +106 -0
- package/dist/sdk/src/agents/load-mcp-config.d.ts +69 -0
- package/dist/sdk/src/client.d.ts +33 -0
- package/dist/sdk/src/constants.d.ts +4 -0
- package/dist/sdk/src/credentials.d.ts +58 -0
- package/dist/sdk/src/custom-tool.d.ts +32 -0
- package/dist/sdk/src/env.d.ts +31 -0
- package/dist/sdk/src/error-utils.d.ts +55 -0
- package/dist/sdk/src/impl/__tests__/prompt-result.test.d.ts +1 -0
- package/dist/sdk/src/impl/agent-runtime.d.ts +8 -0
- package/dist/sdk/src/impl/database.d.ts +7 -0
- package/dist/sdk/src/impl/llm.d.ts +8 -0
- package/dist/sdk/src/impl/model-provider.d.ts +61 -0
- package/dist/sdk/src/index.d.ts +41 -0
- package/dist/sdk/src/native/ripgrep.d.ts +7 -0
- package/dist/sdk/src/retry-config.d.ts +46 -0
- package/dist/sdk/src/run-state.d.ts +81 -0
- package/dist/sdk/src/run.d.ts +79 -0
- package/dist/sdk/src/skills/load-skills.d.ts +42 -0
- package/dist/sdk/src/testing/env.d.ts +5 -0
- package/dist/sdk/src/tools/change-file.d.ts +7 -0
- package/dist/sdk/src/tools/code-search.d.ts +13 -0
- package/dist/sdk/src/tools/glob.d.ts +8 -0
- package/dist/sdk/src/tools/index.d.ts +16 -0
- package/dist/sdk/src/tools/list-directory.d.ts +7 -0
- package/dist/sdk/src/tools/read-files.d.ts +16 -0
- package/dist/sdk/src/tools/run-file-change-hooks.d.ts +4 -0
- package/dist/sdk/src/tools/run-terminal-command.d.ts +8 -0
- package/dist/sdk/src/types/env.d.ts +30 -0
- package/dist/sdk/src/validate-agents.d.ts +45 -0
- package/package.json +1 -1
- package/dist/index.d.ts +0 -3443
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { processFileBlock } from '../../../process-file-block';
|
|
2
|
+
import type { ClientToolCall, LevelCodeToolCall, LevelCodeToolOutput } from '@levelcode/common/tools/list';
|
|
3
|
+
import type { RequestOptionalFileFn } from '@levelcode/common/types/contracts/client';
|
|
4
|
+
import type { Logger } from '@levelcode/common/types/contracts/logger';
|
|
5
|
+
import type { ParamsExcluding } from '@levelcode/common/types/function-params';
|
|
6
|
+
import type { AgentState } from '@levelcode/common/types/session-state';
|
|
7
|
+
type FileProcessingTools = 'write_file' | 'str_replace' | 'create_plan';
|
|
8
|
+
export type FileProcessing<T extends FileProcessingTools = FileProcessingTools> = {
|
|
9
|
+
tool: T;
|
|
10
|
+
path: string;
|
|
11
|
+
toolCallId: string;
|
|
12
|
+
} & ({
|
|
13
|
+
content: string;
|
|
14
|
+
patch?: string;
|
|
15
|
+
messages: string[];
|
|
16
|
+
} | {
|
|
17
|
+
error: string;
|
|
18
|
+
});
|
|
19
|
+
export type FileProcessingState = {
|
|
20
|
+
promisesByPath: Record<string, Promise<FileProcessing>[]>;
|
|
21
|
+
allPromises: Promise<FileProcessing>[];
|
|
22
|
+
fileChangeErrors: Extract<FileProcessing, {
|
|
23
|
+
error: string;
|
|
24
|
+
}>[];
|
|
25
|
+
fileChanges: Exclude<FileProcessing, {
|
|
26
|
+
error: string;
|
|
27
|
+
}>[];
|
|
28
|
+
firstFileProcessed: boolean;
|
|
29
|
+
};
|
|
30
|
+
export declare function getFileProcessingValues(state: FileProcessingState): FileProcessingState;
|
|
31
|
+
export declare const handleWriteFile: (params: {
|
|
32
|
+
previousToolCallFinished: Promise<void>;
|
|
33
|
+
toolCall: LevelCodeToolCall<"write_file">;
|
|
34
|
+
agentState: AgentState;
|
|
35
|
+
clientSessionId: string;
|
|
36
|
+
fileProcessingState: FileProcessingState;
|
|
37
|
+
fingerprintId: string;
|
|
38
|
+
logger: Logger;
|
|
39
|
+
prompt: string | undefined;
|
|
40
|
+
userId: string | undefined;
|
|
41
|
+
userInputId: string;
|
|
42
|
+
requestClientToolCall: (toolCall: ClientToolCall<"write_file">) => Promise<LevelCodeToolOutput<"write_file">>;
|
|
43
|
+
requestOptionalFile: RequestOptionalFileFn;
|
|
44
|
+
writeToClient: (chunk: string) => void;
|
|
45
|
+
} & ParamsExcluding<typeof processFileBlock, "path" | "instructions" | "fingerprintId" | "initialContentPromise" | "newContent" | "messages" | "lastUserPrompt"> & ParamsExcluding<RequestOptionalFileFn, "filePath">) => Promise<{
|
|
46
|
+
output: LevelCodeToolOutput<"write_file">;
|
|
47
|
+
}>;
|
|
48
|
+
export declare function postStreamProcessing<T extends FileProcessingTools>(toolCall: FileProcessing<T>, fileProcessingState: FileProcessingState, writeToClient: (chunk: string) => void, requestClientToolCall: (toolCall: ClientToolCall<T>) => Promise<LevelCodeToolOutput<T>>): Promise<LevelCodeToolOutput<T>>;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { LevelCodeToolCall, LevelCodeToolOutput } from '@levelcode/common/tools/list';
|
|
2
|
+
type ToolName = 'write_todos';
|
|
3
|
+
export declare const handleWriteTodos: (params: {
|
|
4
|
+
previousToolCallFinished: Promise<void>;
|
|
5
|
+
toolCall: LevelCodeToolCall<ToolName>;
|
|
6
|
+
}) => Promise<{
|
|
7
|
+
output: LevelCodeToolOutput<ToolName>;
|
|
8
|
+
}>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { toolParams } from '@levelcode/common/tools/list';
|
|
2
|
+
import z from 'zod/v4';
|
|
3
|
+
import type { SkillsMap } from '@levelcode/common/types/skill';
|
|
4
|
+
import type { CustomToolDefinitions, customToolDefinitionsSchema } from '@levelcode/common/util/file';
|
|
5
|
+
import type { ToolSet } from 'ai';
|
|
6
|
+
/**
|
|
7
|
+
* Ensures the inputSchema is a Zod schema. If it's a JSON Schema object
|
|
8
|
+
* (from SDK custom tools that were serialized), converts it to Zod.
|
|
9
|
+
*/
|
|
10
|
+
export declare function ensureZodSchema(schema: z.ZodType | Record<string, unknown>): z.ZodType;
|
|
11
|
+
export declare function buildToolDescription(params: {
|
|
12
|
+
toolName: string;
|
|
13
|
+
schema: z.ZodType;
|
|
14
|
+
description?: string;
|
|
15
|
+
endsAgentStep: boolean;
|
|
16
|
+
exampleInputs?: any[];
|
|
17
|
+
}): string;
|
|
18
|
+
export declare const toolDescriptions: Record<keyof typeof toolParams, string>;
|
|
19
|
+
export declare const getToolsInstructions: (tools: readonly string[], additionalToolDefinitions: NonNullable<z.input<typeof customToolDefinitionsSchema>>, options?: {
|
|
20
|
+
availableSkillsXml?: string;
|
|
21
|
+
}) => string;
|
|
22
|
+
export declare const fullToolList: (toolNames: readonly string[], additionalToolDefinitions: CustomToolDefinitions, options?: {
|
|
23
|
+
availableSkillsXml?: string;
|
|
24
|
+
}) => string;
|
|
25
|
+
export declare const getShortToolInstructions: (toolNames: readonly string[], additionalToolDefinitions: CustomToolDefinitions) => string;
|
|
26
|
+
export declare function getToolSet(params: {
|
|
27
|
+
toolNames: string[];
|
|
28
|
+
additionalToolDefinitions: () => Promise<CustomToolDefinitions>;
|
|
29
|
+
agentTools: ToolSet;
|
|
30
|
+
skills: SkillsMap;
|
|
31
|
+
}): Promise<ToolSet>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { processStreamWithTools } from '../tool-stream-parser';
|
|
2
|
+
import type { CustomToolCall, ExecuteToolCallParams } from './tool-executor';
|
|
3
|
+
import type { AgentTemplate } from '../templates/types';
|
|
4
|
+
import type { LevelCodeToolCall } from '@levelcode/common/tools/list';
|
|
5
|
+
import type { Logger } from '@levelcode/common/types/contracts/logger';
|
|
6
|
+
import type { ParamsExcluding } from '@levelcode/common/types/function-params';
|
|
7
|
+
import type { Message, ToolMessage } from '@levelcode/common/types/messages/levelcode-message';
|
|
8
|
+
import type { PrintModeEvent } from '@levelcode/common/types/print-mode';
|
|
9
|
+
import type { Subgoal } from '@levelcode/common/types/session-state';
|
|
10
|
+
import type { ProjectFileContext } from '@levelcode/common/util/file';
|
|
11
|
+
export declare function processStream(params: {
|
|
12
|
+
agentContext: Record<string, Subgoal>;
|
|
13
|
+
agentTemplate: AgentTemplate;
|
|
14
|
+
ancestorRunIds: string[];
|
|
15
|
+
fileContext: ProjectFileContext;
|
|
16
|
+
fingerprintId: string;
|
|
17
|
+
fullResponse: string;
|
|
18
|
+
logger: Logger;
|
|
19
|
+
messages: Message[];
|
|
20
|
+
repoId: string | undefined;
|
|
21
|
+
runId: string;
|
|
22
|
+
signal: AbortSignal;
|
|
23
|
+
userId: string | undefined;
|
|
24
|
+
onCostCalculated: (credits: number) => Promise<void>;
|
|
25
|
+
onResponseChunk: (chunk: string | PrintModeEvent) => void;
|
|
26
|
+
} & Omit<ExecuteToolCallParams<any>, 'fileProcessingState' | 'fromHandleSteps' | 'fullResponse' | 'input' | 'previousToolCallFinished' | 'state' | 'toolCallId' | 'toolCalls' | 'toolName' | 'toolResults' | 'toolResultsToAddAfterStream'> & ParamsExcluding<typeof processStreamWithTools, 'processors' | 'defaultProcessor' | 'onError' | 'loggerOptions' | 'executeXmlToolCall'>): Promise<{
|
|
27
|
+
fullResponse: string;
|
|
28
|
+
fullResponseChunks: string[];
|
|
29
|
+
hadToolCallError: boolean;
|
|
30
|
+
messageId: string | null;
|
|
31
|
+
toolCalls: (CustomToolCall | LevelCodeToolCall)[];
|
|
32
|
+
toolResults: ToolMessage[];
|
|
33
|
+
}>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { AgentTemplate } from '../templates/types';
|
|
2
|
+
import type { FileProcessingState } from './handlers/tool/write-file';
|
|
3
|
+
import type { ToolName } from '@levelcode/common/tools/constants';
|
|
4
|
+
import type { LevelCodeToolCall } from '@levelcode/common/tools/list';
|
|
5
|
+
import type { AgentRuntimeDeps, AgentRuntimeScopedDeps } from '@levelcode/common/types/contracts/agent-runtime';
|
|
6
|
+
import type { Logger } from '@levelcode/common/types/contracts/logger';
|
|
7
|
+
import type { ToolMessage } from '@levelcode/common/types/messages/levelcode-message';
|
|
8
|
+
import type { PrintModeEvent } from '@levelcode/common/types/print-mode';
|
|
9
|
+
import type { AgentTemplateType, AgentState, Subgoal } from '@levelcode/common/types/session-state';
|
|
10
|
+
import type { CustomToolDefinitions, ProjectFileContext } from '@levelcode/common/util/file';
|
|
11
|
+
import type { ToolCallPart, ToolSet } from 'ai';
|
|
12
|
+
export type CustomToolCall = {
|
|
13
|
+
toolName: string;
|
|
14
|
+
input: Record<string, unknown>;
|
|
15
|
+
} & Omit<ToolCallPart, 'type'>;
|
|
16
|
+
export type ToolCallError = {
|
|
17
|
+
toolName?: string;
|
|
18
|
+
input: Record<string, unknown>;
|
|
19
|
+
error: string;
|
|
20
|
+
} & Pick<LevelCodeToolCall, 'toolCallId'>;
|
|
21
|
+
export declare function parseRawToolCall<T extends ToolName = ToolName>(params: {
|
|
22
|
+
rawToolCall: {
|
|
23
|
+
toolName: T;
|
|
24
|
+
toolCallId: string;
|
|
25
|
+
input: Record<string, unknown>;
|
|
26
|
+
};
|
|
27
|
+
}): LevelCodeToolCall<T> | ToolCallError;
|
|
28
|
+
export type ExecuteToolCallParams<T extends string = ToolName> = {
|
|
29
|
+
toolName: T;
|
|
30
|
+
input: Record<string, unknown>;
|
|
31
|
+
autoInsertEndStepParam?: boolean;
|
|
32
|
+
excludeToolFromMessageHistory?: boolean;
|
|
33
|
+
agentContext: Record<string, Subgoal>;
|
|
34
|
+
agentState: AgentState;
|
|
35
|
+
agentStepId: string;
|
|
36
|
+
ancestorRunIds: string[];
|
|
37
|
+
agentTemplate: AgentTemplate;
|
|
38
|
+
clientSessionId: string;
|
|
39
|
+
fileContext: ProjectFileContext;
|
|
40
|
+
fileProcessingState: FileProcessingState;
|
|
41
|
+
fingerprintId: string;
|
|
42
|
+
fromHandleSteps?: boolean;
|
|
43
|
+
fullResponse: string;
|
|
44
|
+
localAgentTemplates: Record<string, AgentTemplate>;
|
|
45
|
+
logger: Logger;
|
|
46
|
+
previousToolCallFinished: Promise<void>;
|
|
47
|
+
prompt: string | undefined;
|
|
48
|
+
repoId: string | undefined;
|
|
49
|
+
repoUrl: string | undefined;
|
|
50
|
+
runId: string;
|
|
51
|
+
signal: AbortSignal;
|
|
52
|
+
system: string;
|
|
53
|
+
tools: ToolSet;
|
|
54
|
+
toolCallId: string | undefined;
|
|
55
|
+
toolCalls: (LevelCodeToolCall | CustomToolCall)[];
|
|
56
|
+
toolResults: ToolMessage[];
|
|
57
|
+
toolResultsToAddAfterStream: ToolMessage[];
|
|
58
|
+
skipDirectResultPush?: boolean;
|
|
59
|
+
userId: string | undefined;
|
|
60
|
+
userInputId: string;
|
|
61
|
+
fetch: typeof globalThis.fetch;
|
|
62
|
+
onCostCalculated: (credits: number) => Promise<void>;
|
|
63
|
+
onResponseChunk: (chunk: string | PrintModeEvent) => void;
|
|
64
|
+
} & AgentRuntimeDeps & AgentRuntimeScopedDeps;
|
|
65
|
+
export declare function executeToolCall<T extends ToolName>(params: ExecuteToolCallParams<T>): Promise<void>;
|
|
66
|
+
export declare function parseRawCustomToolCall(params: {
|
|
67
|
+
customToolDefs: CustomToolDefinitions;
|
|
68
|
+
rawToolCall: {
|
|
69
|
+
toolName: string;
|
|
70
|
+
toolCallId: string;
|
|
71
|
+
input: Record<string, unknown>;
|
|
72
|
+
};
|
|
73
|
+
autoInsertEndStepParam?: boolean;
|
|
74
|
+
}): CustomToolCall | ToolCallError;
|
|
75
|
+
export declare function executeCustomToolCall(params: ExecuteToolCallParams<string>): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Checks if a tool name matches a spawnable agent and returns the transformed
|
|
78
|
+
* spawn_agents input if so. Returns null if not an agent tool call.
|
|
79
|
+
*/
|
|
80
|
+
export declare function tryTransformAgentToolCall(params: {
|
|
81
|
+
toolName: string;
|
|
82
|
+
input: Record<string, unknown>;
|
|
83
|
+
spawnableAgents: AgentTemplateType[];
|
|
84
|
+
}): {
|
|
85
|
+
toolName: 'spawn_agents';
|
|
86
|
+
input: Record<string, unknown>;
|
|
87
|
+
} | null;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { System } from '../llm-api/claude';
|
|
2
|
+
import type { Logger } from '@levelcode/common/types/contracts/logger';
|
|
3
|
+
import type { Message } from '@levelcode/common/types/messages/levelcode-message';
|
|
4
|
+
import type { TextPart, ImagePart } from '@levelcode/common/types/messages/content-part';
|
|
5
|
+
export declare function messagesWithSystem(params: {
|
|
6
|
+
messages: Message[];
|
|
7
|
+
system: System;
|
|
8
|
+
}): Message[];
|
|
9
|
+
export declare function asUserMessage(str: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Combines prompt, params, and content into a unified message content structure.
|
|
12
|
+
* Always wraps the first text part in <user_message> tags for consistent XML framing.
|
|
13
|
+
* If you need a specific text part wrapped, put it first or pre-wrap it yourself before calling.
|
|
14
|
+
*/
|
|
15
|
+
export declare function buildUserMessageContent(prompt: string | undefined, params: Record<string, any> | undefined, content?: Array<TextPart | ImagePart>): Array<TextPart | ImagePart>;
|
|
16
|
+
export declare function parseUserMessage(str: string): string | undefined;
|
|
17
|
+
export declare function withSystemInstructionTags(str: string): string;
|
|
18
|
+
export declare function withSystemTags(str: string): string;
|
|
19
|
+
export declare function castAssistantMessage(message: Message): Message | null;
|
|
20
|
+
/**
|
|
21
|
+
* Trims messages from the beginning to fit within token limits while preserving
|
|
22
|
+
* important content. Also simplifies terminal command outputs to save tokens.
|
|
23
|
+
*
|
|
24
|
+
* The function:
|
|
25
|
+
* 1. Processes messages from newest to oldest
|
|
26
|
+
* 2. Simplifies terminal command outputs after keeping N most recent ones
|
|
27
|
+
* 3. Stops adding messages when approaching token limit
|
|
28
|
+
*
|
|
29
|
+
* @param messages - Array of messages to trim
|
|
30
|
+
* @param systemTokens - Number of tokens used by system prompt
|
|
31
|
+
* @param maxTotalTokens - Maximum total tokens allowed, defaults to 200k
|
|
32
|
+
* @returns Trimmed array of messages that fits within token limit
|
|
33
|
+
*/
|
|
34
|
+
export declare function trimMessagesToFitTokenLimit(params: {
|
|
35
|
+
messages: Message[];
|
|
36
|
+
systemTokens: number;
|
|
37
|
+
maxTotalTokens?: number;
|
|
38
|
+
logger: Logger;
|
|
39
|
+
}): Message[];
|
|
40
|
+
export declare function getMessagesSubset(params: {
|
|
41
|
+
messages: Message[];
|
|
42
|
+
otherTokens: number;
|
|
43
|
+
logger: Logger;
|
|
44
|
+
}): Message[];
|
|
45
|
+
export declare function expireMessages(messages: Message[], endOf: 'agentStep' | 'userPrompt'): Message[];
|
|
46
|
+
/**
|
|
47
|
+
* Removes tool calls from the message history that don't have corresponding tool responses.
|
|
48
|
+
* This is important when passing message history to spawned agents, as unfinished tool calls
|
|
49
|
+
* will cause issues with the LLM expecting tool responses.
|
|
50
|
+
*
|
|
51
|
+
* The function:
|
|
52
|
+
* 1. Collects all toolCallIds from tool response messages
|
|
53
|
+
* 2. Filters assistant messages to remove tool-call content parts without responses
|
|
54
|
+
* 3. Removes assistant messages that become empty after filtering
|
|
55
|
+
*/
|
|
56
|
+
export declare function filterUnfinishedToolCalls(messages: Message[]): Message[];
|
|
57
|
+
export declare function getEditedFiles(params: {
|
|
58
|
+
messages: Message[];
|
|
59
|
+
logger: Logger;
|
|
60
|
+
}): string[];
|
|
61
|
+
export declare function getPreviouslyReadFiles(params: {
|
|
62
|
+
messages: Message[];
|
|
63
|
+
logger: Logger;
|
|
64
|
+
}): {
|
|
65
|
+
path: string;
|
|
66
|
+
content: string;
|
|
67
|
+
referencedBy?: Record<string, string[]>;
|
|
68
|
+
}[];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type ParsedToolCallFromText = {
|
|
2
|
+
type: 'tool_call';
|
|
3
|
+
toolName: string;
|
|
4
|
+
input: Record<string, unknown>;
|
|
5
|
+
};
|
|
6
|
+
export type ParsedTextSegment = {
|
|
7
|
+
type: 'text';
|
|
8
|
+
text: string;
|
|
9
|
+
};
|
|
10
|
+
export type ParsedSegment = ParsedToolCallFromText | ParsedTextSegment;
|
|
11
|
+
/**
|
|
12
|
+
* Parses text containing tool calls in the <levelcode_tool_call> XML format,
|
|
13
|
+
* returning interleaved text and tool call segments in order.
|
|
14
|
+
*
|
|
15
|
+
* Example input:
|
|
16
|
+
* ```
|
|
17
|
+
* Some text before
|
|
18
|
+
* <levelcode_tool_call>
|
|
19
|
+
* {
|
|
20
|
+
* "cb_tool_name": "read_files",
|
|
21
|
+
* "paths": ["file.ts"]
|
|
22
|
+
* }
|
|
23
|
+
* </levelcode_tool_call>
|
|
24
|
+
* Some text after
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @param text - The text containing tool calls in XML format
|
|
28
|
+
* @returns Array of segments (text and tool calls) in order of appearance
|
|
29
|
+
*/
|
|
30
|
+
export declare function parseTextWithToolCalls(text: string): ParsedSegment[];
|
|
31
|
+
/**
|
|
32
|
+
* Parses tool calls from text in the <levelcode_tool_call> XML format.
|
|
33
|
+
* This is a convenience function that returns only tool calls (no text segments).
|
|
34
|
+
*
|
|
35
|
+
* @param text - The text containing tool calls in XML format
|
|
36
|
+
* @returns Array of parsed tool calls with toolName and input
|
|
37
|
+
*/
|
|
38
|
+
export declare function parseToolCallsFromText(text: string): Omit<ParsedToolCallFromText, 'type'>[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface TokenCallerMap {
|
|
2
|
+
[filePath: string]: {
|
|
3
|
+
[token: string]: string[];
|
|
4
|
+
};
|
|
5
|
+
}
|
|
6
|
+
export declare function renderReadFilesResult(files: {
|
|
7
|
+
path: string;
|
|
8
|
+
content: string;
|
|
9
|
+
}[], tokenCallers: TokenCallerMap): {
|
|
10
|
+
path: string;
|
|
11
|
+
content: string;
|
|
12
|
+
referencedBy: {
|
|
13
|
+
[token: string]: string[];
|
|
14
|
+
};
|
|
15
|
+
}[];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { LevelCodeToolOutput } from '@levelcode/common/tools/list';
|
|
2
|
+
import type { Logger } from '@levelcode/common/types/contracts/logger';
|
|
3
|
+
export declare function simplifyReadFileResults(messageContent: LevelCodeToolOutput<'read_files'>): LevelCodeToolOutput<'read_files'>;
|
|
4
|
+
export declare function simplifyTerminalCommandResults(params: {
|
|
5
|
+
messageContent: LevelCodeToolOutput<'run_terminal_command'>;
|
|
6
|
+
logger: Logger;
|
|
7
|
+
}): LevelCodeToolOutput<'run_terminal_command'>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stateful stream XML parser that extracts tool calls from <levelcode_tool_call> XML
|
|
3
|
+
* and filters them out of the text stream.
|
|
4
|
+
*
|
|
5
|
+
* Handles partial tags at chunk boundaries using a stateful approach.
|
|
6
|
+
*/
|
|
7
|
+
export type ParsedToolCall = {
|
|
8
|
+
toolName: string;
|
|
9
|
+
input: Record<string, unknown>;
|
|
10
|
+
};
|
|
11
|
+
export type StreamParserState = {
|
|
12
|
+
/** Buffer for holding partial content when inside a tool call tag or at boundaries */
|
|
13
|
+
buffer: string;
|
|
14
|
+
/** Whether we're currently inside a tool call tag */
|
|
15
|
+
insideToolCall: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type ParseResult = {
|
|
18
|
+
/** Filtered text with tool call XML removed */
|
|
19
|
+
filteredText: string;
|
|
20
|
+
/** Tool calls extracted from this chunk */
|
|
21
|
+
toolCalls: ParsedToolCall[];
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Creates initial parser state
|
|
25
|
+
*/
|
|
26
|
+
export declare function createStreamParserState(): StreamParserState;
|
|
27
|
+
/**
|
|
28
|
+
* Parses a stream chunk, extracting tool calls and filtering out the XML.
|
|
29
|
+
*
|
|
30
|
+
* @param chunk - The incoming text chunk
|
|
31
|
+
* @param state - Mutable parser state (updated in place)
|
|
32
|
+
* @returns Filtered text and any extracted tool calls
|
|
33
|
+
*/
|
|
34
|
+
export declare function parseStreamChunk(chunk: string, state: StreamParserState): ParseResult;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import './types';
|
|
2
|
+
import { Language, Parser, Query } from 'web-tree-sitter';
|
|
3
|
+
export interface LanguageConfig {
|
|
4
|
+
extensions: string[];
|
|
5
|
+
wasmFile: string;
|
|
6
|
+
queryPathOrContent: string;
|
|
7
|
+
parser?: Parser;
|
|
8
|
+
query?: Query;
|
|
9
|
+
language?: Language;
|
|
10
|
+
}
|
|
11
|
+
export interface RuntimeLanguageLoader {
|
|
12
|
+
loadLanguage(wasmFile: string): Promise<Language>;
|
|
13
|
+
initParser(): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export declare const WASM_FILES: {
|
|
16
|
+
readonly 'tree-sitter-c-sharp.wasm': "tree-sitter-c-sharp.wasm";
|
|
17
|
+
readonly 'tree-sitter-cpp.wasm': "tree-sitter-cpp.wasm";
|
|
18
|
+
readonly 'tree-sitter-go.wasm': "tree-sitter-go.wasm";
|
|
19
|
+
readonly 'tree-sitter-java.wasm': "tree-sitter-java.wasm";
|
|
20
|
+
readonly 'tree-sitter-javascript.wasm': "tree-sitter-javascript.wasm";
|
|
21
|
+
readonly 'tree-sitter-python.wasm': "tree-sitter-python.wasm";
|
|
22
|
+
readonly 'tree-sitter-ruby.wasm': "tree-sitter-ruby.wasm";
|
|
23
|
+
readonly 'tree-sitter-rust.wasm': "tree-sitter-rust.wasm";
|
|
24
|
+
readonly 'tree-sitter-tsx.wasm': "tree-sitter-tsx.wasm";
|
|
25
|
+
readonly 'tree-sitter-typescript.wasm': "tree-sitter-typescript.wasm";
|
|
26
|
+
};
|
|
27
|
+
export declare const languageTable: LanguageConfig[];
|
|
28
|
+
/**
|
|
29
|
+
* Set a custom WASM directory for loading tree-sitter WASM files.
|
|
30
|
+
* This can be useful for custom packaging or deployment scenarios.
|
|
31
|
+
*/
|
|
32
|
+
export declare function setWasmDir(dir: string): void;
|
|
33
|
+
export declare function getWasmDir(): string | undefined;
|
|
34
|
+
export declare function findLanguageConfigByExtension(filePath: string): LanguageConfig | undefined;
|
|
35
|
+
export declare function createLanguageConfig(filePath: string, runtimeLoader: RuntimeLanguageLoader): Promise<LanguageConfig | undefined>;
|
|
36
|
+
export declare function getLanguageConfig(filePath: string): Promise<LanguageConfig | undefined>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { LanguageConfig } from './languages';
|
|
2
|
+
export declare const DEBUG_PARSING = false;
|
|
3
|
+
export interface TokenCallerMap {
|
|
4
|
+
[filePath: string]: {
|
|
5
|
+
[token: string]: string[];
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export interface FileTokenData {
|
|
9
|
+
tokenScores: {
|
|
10
|
+
[filePath: string]: {
|
|
11
|
+
[token: string]: number;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
tokenCallers: TokenCallerMap;
|
|
15
|
+
}
|
|
16
|
+
export declare function getFileTokenScores(projectRoot: string, filePaths: string[], readFile?: (filePath: string) => string | null): Promise<FileTokenData>;
|
|
17
|
+
export declare function parseTokens(filePath: string, languageConfig: LanguageConfig, readFile?: (filePath: string) => string | null): {
|
|
18
|
+
numLines: number;
|
|
19
|
+
identifiers: string[];
|
|
20
|
+
calls: string[];
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getDirnameDynamically(): string | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { AgentDefinition } from '@levelcode/common/templates/initial-agents-dir/types/agent-definition';
|
|
2
|
+
/**
|
|
3
|
+
* Agent definition with source file path metadata.
|
|
4
|
+
*/
|
|
5
|
+
export type LoadedAgentDefinition = AgentDefinition & {
|
|
6
|
+
/** The file path this agent was loaded from */
|
|
7
|
+
_sourceFilePath: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Loaded agent definitions keyed by agent ID.
|
|
11
|
+
*/
|
|
12
|
+
export type LoadedAgents = Record<string, LoadedAgentDefinition>;
|
|
13
|
+
/**
|
|
14
|
+
* Resolves environment variable references in MCP server configs.
|
|
15
|
+
* Values starting with `$` are treated as env var references (e.g., `'$NOTION_TOKEN'`).
|
|
16
|
+
*
|
|
17
|
+
* @param env - The env object from MCP config with possible $VAR_NAME references
|
|
18
|
+
* @param agentId - The agent ID for error messages
|
|
19
|
+
* @param mcpServerName - The MCP server name for error messages
|
|
20
|
+
* @returns Resolved env object with all $VAR_NAME values replaced with actual values
|
|
21
|
+
* @throws Error if a referenced environment variable is missing
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolveMcpEnv(env: Record<string, string> | undefined, agentId: string, mcpServerName: string): Record<string, string>;
|
|
24
|
+
/**
|
|
25
|
+
* Resolves all MCP server env references in an agent definition.
|
|
26
|
+
* Mutates the mcpServers object to replace $VAR_NAME references with resolved values.
|
|
27
|
+
*
|
|
28
|
+
* @param agent - The agent definition to process
|
|
29
|
+
* @throws Error if any referenced environment variable is missing
|
|
30
|
+
*/
|
|
31
|
+
export declare function resolveAgentMcpEnv(agent: AgentDefinition): void;
|
|
32
|
+
/**
|
|
33
|
+
* Validation error for an agent that failed validation.
|
|
34
|
+
*/
|
|
35
|
+
export type AgentValidationError = {
|
|
36
|
+
/** The agent's ID */
|
|
37
|
+
agentId: string;
|
|
38
|
+
/** The source file path where the agent was loaded from */
|
|
39
|
+
filePath: string;
|
|
40
|
+
/** The validation error message */
|
|
41
|
+
message: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Result returned by loadLocalAgents when validate: true.
|
|
45
|
+
* Contains both the valid agents and any validation errors.
|
|
46
|
+
*/
|
|
47
|
+
export type LoadLocalAgentsResult = {
|
|
48
|
+
/** Valid agent definitions that passed validation */
|
|
49
|
+
agents: LoadedAgents;
|
|
50
|
+
/** Validation errors for agents that failed validation */
|
|
51
|
+
validationErrors: AgentValidationError[];
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Load agent definitions from `.agents` directories.
|
|
55
|
+
*
|
|
56
|
+
* By default, searches for agents in:
|
|
57
|
+
* - `{cwd}/.agents`
|
|
58
|
+
* - `{cwd}/../.agents`
|
|
59
|
+
* - `{homedir}/.agents`
|
|
60
|
+
*
|
|
61
|
+
* Agent files can be `.ts`, `.tsx`, `.js`, `.mjs`, or `.cjs`.
|
|
62
|
+
* TypeScript files are loaded natively by Bun's runtime.
|
|
63
|
+
*
|
|
64
|
+
* @param options.agentsPath - Optional path to a specific agents directory
|
|
65
|
+
* @param options.verbose - Whether to log errors during loading
|
|
66
|
+
* @param options.validate - Whether to validate agents after loading
|
|
67
|
+
* @returns When validate is false/omitted: Record of agent definitions keyed by agent ID.
|
|
68
|
+
* When validate is true: Object with valid agents and validation errors.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* // Load from default locations
|
|
73
|
+
* const agents = await loadLocalAgents({ verbose: true })
|
|
74
|
+
*
|
|
75
|
+
* // Load from a specific directory
|
|
76
|
+
* const agents = await loadLocalAgents({ agentsPath: './my-agents' })
|
|
77
|
+
*
|
|
78
|
+
* // Load and validate agents - returns both valid agents and errors
|
|
79
|
+
* const { agents, validationErrors } = await loadLocalAgents({ validate: true })
|
|
80
|
+
* if (validationErrors.length > 0) {
|
|
81
|
+
* console.error('Some agents failed validation:', validationErrors)
|
|
82
|
+
* }
|
|
83
|
+
*
|
|
84
|
+
* // Access source file path for debugging
|
|
85
|
+
* for (const agent of Object.values(agents)) {
|
|
86
|
+
* console.log(`${agent.id} loaded from ${agent._sourceFilePath}`)
|
|
87
|
+
* }
|
|
88
|
+
*
|
|
89
|
+
* // Use with client.run()
|
|
90
|
+
* const result = await client.run({
|
|
91
|
+
* agent: 'my-agent',
|
|
92
|
+
* agentDefinitions: Object.values(agents),
|
|
93
|
+
* prompt: 'Hello',
|
|
94
|
+
* })
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare function loadLocalAgents(options: {
|
|
98
|
+
agentsPath?: string;
|
|
99
|
+
verbose?: boolean;
|
|
100
|
+
validate: true;
|
|
101
|
+
}): Promise<LoadLocalAgentsResult>;
|
|
102
|
+
export declare function loadLocalAgents(options: {
|
|
103
|
+
agentsPath?: string;
|
|
104
|
+
verbose?: boolean;
|
|
105
|
+
validate?: false;
|
|
106
|
+
}): Promise<LoadedAgents>;
|