@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,176 @@
|
|
|
1
|
+
import { z } from 'zod/v4';
|
|
2
|
+
import type { GrantType } from './types/grant';
|
|
3
|
+
import type { MCPConfig } from './types/mcp';
|
|
4
|
+
import type { ToolMessage } from './types/messages/levelcode-message';
|
|
5
|
+
import type { TextPart, ImagePart, ToolResultOutput } from './types/messages/content-part';
|
|
6
|
+
import type { PrintModeEvent } from './types/print-mode';
|
|
7
|
+
import type { AgentOutput, SessionState, ToolCall } from './types/session-state';
|
|
8
|
+
import type { ProjectFileContext } from './util/file';
|
|
9
|
+
export declare const FileChangeSchema: z.ZodObject<{
|
|
10
|
+
type: z.ZodEnum<{
|
|
11
|
+
file: "file";
|
|
12
|
+
patch: "patch";
|
|
13
|
+
}>;
|
|
14
|
+
path: z.ZodString;
|
|
15
|
+
content: z.ZodString;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
export type FileChange = z.infer<typeof FileChangeSchema>;
|
|
18
|
+
export declare const CHANGES: z.ZodArray<z.ZodObject<{
|
|
19
|
+
type: z.ZodEnum<{
|
|
20
|
+
file: "file";
|
|
21
|
+
patch: "patch";
|
|
22
|
+
}>;
|
|
23
|
+
path: z.ZodString;
|
|
24
|
+
content: z.ZodString;
|
|
25
|
+
}, z.core.$strip>>;
|
|
26
|
+
export type FileChanges = z.infer<typeof CHANGES>;
|
|
27
|
+
type ClientActionPrompt = {
|
|
28
|
+
type: 'prompt';
|
|
29
|
+
promptId: string;
|
|
30
|
+
prompt: string | undefined;
|
|
31
|
+
content?: (TextPart | ImagePart)[];
|
|
32
|
+
promptParams?: Record<string, any>;
|
|
33
|
+
fingerprintId: string;
|
|
34
|
+
authToken?: string;
|
|
35
|
+
costMode?: string;
|
|
36
|
+
sessionState: SessionState;
|
|
37
|
+
toolResults: ToolMessage[];
|
|
38
|
+
model?: string;
|
|
39
|
+
repoUrl?: string;
|
|
40
|
+
agentId?: string;
|
|
41
|
+
};
|
|
42
|
+
type ClientActionReadFilesResponse = {
|
|
43
|
+
type: 'read-files-response';
|
|
44
|
+
files: Record<string, string | null>;
|
|
45
|
+
requestId?: string;
|
|
46
|
+
};
|
|
47
|
+
type ClientActionInit = {
|
|
48
|
+
type: 'init';
|
|
49
|
+
fingerprintId: string;
|
|
50
|
+
authToken?: string;
|
|
51
|
+
fileContext: ProjectFileContext;
|
|
52
|
+
repoUrl?: string;
|
|
53
|
+
};
|
|
54
|
+
type ClientActionToolCallResponse = {
|
|
55
|
+
type: 'tool-call-response';
|
|
56
|
+
requestId: string;
|
|
57
|
+
output: ToolResultOutput[];
|
|
58
|
+
};
|
|
59
|
+
type ClientActionCancelUserInput = {
|
|
60
|
+
type: 'cancel-user-input';
|
|
61
|
+
authToken: string;
|
|
62
|
+
promptId: string;
|
|
63
|
+
};
|
|
64
|
+
type ClientActionMcpToolData = {
|
|
65
|
+
type: 'mcp-tool-data';
|
|
66
|
+
requestId: string;
|
|
67
|
+
tools: {
|
|
68
|
+
name: string;
|
|
69
|
+
description?: string;
|
|
70
|
+
inputSchema: {
|
|
71
|
+
type: 'object';
|
|
72
|
+
[k: string]: unknown;
|
|
73
|
+
};
|
|
74
|
+
}[];
|
|
75
|
+
};
|
|
76
|
+
type ClientActionAny = ClientActionPrompt | ClientActionReadFilesResponse | ClientActionInit | ClientActionToolCallResponse | ClientActionCancelUserInput | ClientActionMcpToolData;
|
|
77
|
+
type ClientActionType = ClientActionAny['type'];
|
|
78
|
+
export type ClientAction<T extends ClientActionType = ClientActionType> = {
|
|
79
|
+
[K in ClientActionType]: Extract<ClientActionAny, {
|
|
80
|
+
type: K;
|
|
81
|
+
}>;
|
|
82
|
+
}[T];
|
|
83
|
+
type ServerActionResponseChunk = {
|
|
84
|
+
type: 'response-chunk';
|
|
85
|
+
userInputId: string;
|
|
86
|
+
chunk: string | PrintModeEvent;
|
|
87
|
+
};
|
|
88
|
+
type ServerActionSubagentResponseChunk = {
|
|
89
|
+
type: 'subagent-response-chunk';
|
|
90
|
+
userInputId: string;
|
|
91
|
+
agentId: string;
|
|
92
|
+
agentType: string;
|
|
93
|
+
chunk: string;
|
|
94
|
+
prompt?: string;
|
|
95
|
+
forwardToPrompt?: boolean;
|
|
96
|
+
};
|
|
97
|
+
type ServerActionHandleStepsLogChunk = {
|
|
98
|
+
type: 'handlesteps-log-chunk';
|
|
99
|
+
userInputId: string;
|
|
100
|
+
agentId: string;
|
|
101
|
+
level: 'debug' | 'info' | 'warn' | 'error';
|
|
102
|
+
data: any;
|
|
103
|
+
message?: string;
|
|
104
|
+
};
|
|
105
|
+
export type PromptResponse = {
|
|
106
|
+
type: 'prompt-response';
|
|
107
|
+
promptId: string;
|
|
108
|
+
sessionState: SessionState;
|
|
109
|
+
toolCalls?: ToolCall[];
|
|
110
|
+
toolResults?: ToolMessage[];
|
|
111
|
+
output?: AgentOutput;
|
|
112
|
+
};
|
|
113
|
+
type ServerActionReadFiles = {
|
|
114
|
+
type: 'read-files';
|
|
115
|
+
filePaths: string[];
|
|
116
|
+
requestId: string;
|
|
117
|
+
};
|
|
118
|
+
type ServerActionToolCallRequest = {
|
|
119
|
+
type: 'tool-call-request';
|
|
120
|
+
userInputId: string;
|
|
121
|
+
requestId: string;
|
|
122
|
+
toolName: string;
|
|
123
|
+
input: Record<string, any>;
|
|
124
|
+
timeout?: number;
|
|
125
|
+
mcpConfig?: MCPConfig;
|
|
126
|
+
};
|
|
127
|
+
export type InitResponse = {
|
|
128
|
+
type: 'init-response';
|
|
129
|
+
message?: string;
|
|
130
|
+
agentNames?: Record<string, string>;
|
|
131
|
+
} & Omit<UsageResponse, 'type'>;
|
|
132
|
+
export type UsageResponse = {
|
|
133
|
+
type: 'usage-response';
|
|
134
|
+
usage: number;
|
|
135
|
+
remainingBalance: number;
|
|
136
|
+
balanceBreakdown?: Record<GrantType, number>;
|
|
137
|
+
next_quota_reset: Date | null;
|
|
138
|
+
autoTopupAdded?: number;
|
|
139
|
+
autoTopupEnabled?: boolean;
|
|
140
|
+
};
|
|
141
|
+
export type MessageCostResponse = {
|
|
142
|
+
type: 'message-cost-response';
|
|
143
|
+
promptId: string;
|
|
144
|
+
credits: number;
|
|
145
|
+
agentId?: string;
|
|
146
|
+
};
|
|
147
|
+
type ServerActionActionError = {
|
|
148
|
+
type: 'action-error';
|
|
149
|
+
message: string;
|
|
150
|
+
error?: string;
|
|
151
|
+
remainingBalance?: number;
|
|
152
|
+
};
|
|
153
|
+
type ServerActionPromptError = {
|
|
154
|
+
type: 'prompt-error';
|
|
155
|
+
userInputId: string;
|
|
156
|
+
message: string;
|
|
157
|
+
error?: string;
|
|
158
|
+
remainingBalance?: number;
|
|
159
|
+
};
|
|
160
|
+
type ServerActionRequestReconnect = {
|
|
161
|
+
type: 'request-reconnect';
|
|
162
|
+
};
|
|
163
|
+
type ServerActionRequestMcpToolData = {
|
|
164
|
+
type: 'request-mcp-tool-data';
|
|
165
|
+
requestId: string;
|
|
166
|
+
mcpConfig: MCPConfig;
|
|
167
|
+
toolNames?: string[];
|
|
168
|
+
};
|
|
169
|
+
type ServerActionAny = ServerActionResponseChunk | ServerActionSubagentResponseChunk | ServerActionHandleStepsLogChunk | PromptResponse | ServerActionReadFiles | ServerActionToolCallRequest | InitResponse | UsageResponse | MessageCostResponse | ServerActionActionError | ServerActionPromptError | ServerActionRequestReconnect | ServerActionRequestMcpToolData;
|
|
170
|
+
type ServerActionType = ServerActionAny['type'];
|
|
171
|
+
export type ServerAction<T extends ServerActionType = ServerActionType> = {
|
|
172
|
+
[K in ServerActionType]: Extract<ServerActionAny, {
|
|
173
|
+
type: K;
|
|
174
|
+
}>;
|
|
175
|
+
}[T];
|
|
176
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared analytics core module.
|
|
3
|
+
* Provides common interfaces, types, and utilities used by both
|
|
4
|
+
* server-side (common/src/analytics.ts) and CLI (cli/src/utils/analytics.ts) analytics.
|
|
5
|
+
*/
|
|
6
|
+
/** Interface for PostHog client methods used for event capture */
|
|
7
|
+
export interface AnalyticsClient {
|
|
8
|
+
capture: (params: {
|
|
9
|
+
distinctId: string;
|
|
10
|
+
event: string;
|
|
11
|
+
properties?: Record<string, any>;
|
|
12
|
+
}) => void;
|
|
13
|
+
flush: () => Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
/** Extended client interface with identify, alias, and exception capture (used by CLI) */
|
|
16
|
+
export interface AnalyticsClientWithIdentify extends AnalyticsClient {
|
|
17
|
+
identify: (params: {
|
|
18
|
+
distinctId: string;
|
|
19
|
+
properties?: Record<string, any>;
|
|
20
|
+
}) => void;
|
|
21
|
+
/** Links an alias (previous anonymous ID) to a distinctId (real user ID) */
|
|
22
|
+
alias: (data: {
|
|
23
|
+
distinctId: string;
|
|
24
|
+
alias: string;
|
|
25
|
+
}) => void;
|
|
26
|
+
captureException: (error: any, distinctId: string, properties?: Record<string, any>) => void;
|
|
27
|
+
}
|
|
28
|
+
/** Environment name type */
|
|
29
|
+
export type AnalyticsEnvName = 'dev' | 'test' | 'prod';
|
|
30
|
+
/** Base analytics configuration */
|
|
31
|
+
export interface AnalyticsConfig {
|
|
32
|
+
envName: AnalyticsEnvName;
|
|
33
|
+
posthogApiKey: string;
|
|
34
|
+
posthogHostUrl: string;
|
|
35
|
+
}
|
|
36
|
+
/** Options for creating a PostHog client */
|
|
37
|
+
export interface PostHogClientOptions {
|
|
38
|
+
host: string;
|
|
39
|
+
flushAt?: number;
|
|
40
|
+
flushInterval?: number;
|
|
41
|
+
enableExceptionAutocapture?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Default PostHog client factory.
|
|
45
|
+
* Creates a real PostHog client instance.
|
|
46
|
+
*/
|
|
47
|
+
export declare function createPostHogClient(apiKey: string, options: PostHogClientOptions): AnalyticsClientWithIdentify;
|
|
48
|
+
/**
|
|
49
|
+
* Generates a unique anonymous ID for pre-login tracking.
|
|
50
|
+
* Uses crypto.randomUUID() for uniqueness.
|
|
51
|
+
*/
|
|
52
|
+
export declare function generateAnonymousId(): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AnalyticsEvent } from './constants/analytics-events';
|
|
2
|
+
import type { Logger } from '@levelcode/common/types/contracts/logger';
|
|
3
|
+
export declare function flushAnalytics(logger?: Logger): Promise<void>;
|
|
4
|
+
export declare function trackEvent({ event, userId, properties, logger, }: {
|
|
5
|
+
event: AnalyticsEvent;
|
|
6
|
+
userId: string;
|
|
7
|
+
properties?: Record<string, any>;
|
|
8
|
+
logger: Logger;
|
|
9
|
+
}): void;
|