@evandu/super-pi-server 0.0.0-stage → 0.1.260
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 +250 -3
- package/agents/code-auditor.md +64 -0
- package/agents/code-designer.md +64 -0
- package/agents/coder.md +24 -0
- package/agents/critic.md +24 -0
- package/agents/document-organizer.md +48 -0
- package/agents/patcher.md +27 -0
- package/agents/planner.md +30 -0
- package/agents/project-leader.md +28 -0
- package/agents/reviewer.md +27 -0
- package/agents/scout.md +27 -0
- package/agents/solution-designer.md +62 -0
- package/agents/super-pi-documents/index.ts +92 -0
- package/agents/super-pi-feishu/index.ts +88 -0
- package/agents/super-pi-knowledge/index.ts +70 -0
- package/agents/super-pi-managed-model/index.ts +9 -0
- package/agents/super-pi-memory/index.ts +75 -0
- package/agents/super-pi-native-tools/index.ts +1 -0
- package/agents/super-pi-task/core.ts +2262 -0
- package/agents/super-pi-task/index.ts +814 -0
- package/agents/super-pi-task/workflow-schema.ts +34 -0
- package/agents/super-pi-web/index.ts +32 -0
- package/agents/verifier.md +25 -0
- package/assets/fonts/LICENSE +92 -0
- package/assets/fonts/NotoSansSC-Bold.otf +0 -0
- package/assets/fonts/NotoSansSC-Regular.otf +0 -0
- package/assets/knowledge-model/README.md +37 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/config.json +31 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/onnx/model_quantized.onnx +0 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/special_tokens_map.json +7 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/tokenizer.json +21278 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/tokenizer_config.json +15 -0
- package/assets/knowledge-model/Xenova/bge-small-zh-v1.5/vocab.txt +21128 -0
- package/bin/npm-prefix.d.ts +1 -0
- package/bin/npm-prefix.js +10 -0
- package/bin/super-pi.js +349 -0
- package/dist/client/.super-pi-client-sources.json +82 -0
- package/dist/client/assets/CodeMirrorEditor-mi9rGUce.js +2 -0
- package/dist/client/assets/GitDiffEditor-CpoDDQrA.css +1 -0
- package/dist/client/assets/GitDiffEditor-FQBfGxOY.js +29 -0
- package/dist/client/assets/diff-ChtP43wD.js +1 -0
- package/dist/client/assets/dist-AW5lyI3I.js +1 -0
- package/dist/client/assets/dist-B3-a6uF0.js +7 -0
- package/dist/client/assets/dist-BGxkyh6e.js +1 -0
- package/dist/client/assets/dist-BJxfd7yb.js +11 -0
- package/dist/client/assets/dist-BRVQKlcp.js +1 -0
- package/dist/client/assets/dist-BV64A9Ji.js +1 -0
- package/dist/client/assets/dist-BXAOrsjq.js +1 -0
- package/dist/client/assets/dist-CKF2Jksy.js +1 -0
- package/dist/client/assets/dist-CX_Hm4GS.js +1 -0
- package/dist/client/assets/dist-Cus6_oaF.js +2 -0
- package/dist/client/assets/dist-Cx00EZKR.js +23 -0
- package/dist/client/assets/dist-D71y2EI1.js +1 -0
- package/dist/client/assets/dist-D978o95T.js +5 -0
- package/dist/client/assets/dist-Dc1MBGAG.js +1 -0
- package/dist/client/assets/dist-Dds-qLxY.js +9 -0
- package/dist/client/assets/dist-DeD9copn.js +1 -0
- package/dist/client/assets/dist-DuvGReu-.js +6 -0
- package/dist/client/assets/dist-Dvb0SqcK.js +2 -0
- package/dist/client/assets/dist-J6XWqRpB.js +3 -0
- package/dist/client/assets/dist-QzbOCAU6.js +1 -0
- package/dist/client/assets/dist-moiMRpw_.js +1 -0
- package/dist/client/assets/dist-scBkrwv-.js +2 -0
- package/dist/client/assets/dockerfile-BDePf5PZ.js +1 -0
- package/dist/client/assets/index-Cn7hdrDw.js +350 -0
- package/dist/client/assets/index-UfzqdECL.css +1 -0
- package/dist/client/assets/powershell-D8WpQPaX.js +1 -0
- package/dist/client/assets/properties-C357ku5U.js +1 -0
- package/dist/client/assets/rolldown-runtime-XKyaHtl9.js +1 -0
- package/dist/client/assets/ruby-ChfNwlCY.js +1 -0
- package/dist/client/assets/shell-DwuoZtxw.js +1 -0
- package/dist/client/assets/swift-DKB6_1j6.js +1 -0
- package/dist/client/assets/toml-BPTmHmyx.js +1 -0
- package/dist/client/favicon.ico +0 -0
- package/dist/client/favicon.png +0 -0
- package/dist/client/favicon.svg +10 -0
- package/dist/client/index.html +18 -0
- package/dist/extension.d.ts +15 -0
- package/dist/extension.js +126 -0
- package/dist/server/active-memory.d.ts +247 -0
- package/dist/server/active-memory.js +669 -0
- package/dist/server/agents.d.ts +245 -0
- package/dist/server/agents.js +701 -0
- package/dist/server/application/catalog-service.d.ts +98 -0
- package/dist/server/application/catalog-service.js +245 -0
- package/dist/server/application/conversation-service.d.ts +245 -0
- package/dist/server/application/conversation-service.js +654 -0
- package/dist/server/application/document-service.d.ts +68 -0
- package/dist/server/application/document-service.js +120 -0
- package/dist/server/application/extension-ui-service.d.ts +44 -0
- package/dist/server/application/extension-ui-service.js +135 -0
- package/dist/server/application/feishu-service.d.ts +179 -0
- package/dist/server/application/feishu-service.js +358 -0
- package/dist/server/application/group-chat-service.d.ts +75 -0
- package/dist/server/application/group-chat-service.js +953 -0
- package/dist/server/application/group-execution.d.ts +15 -0
- package/dist/server/application/group-execution.js +77 -0
- package/dist/server/application/project-service.d.ts +464 -0
- package/dist/server/application/project-service.js +2523 -0
- package/dist/server/application/provider-service.d.ts +174 -0
- package/dist/server/application/provider-service.js +510 -0
- package/dist/server/application/run-service.d.ts +547 -0
- package/dist/server/application/run-service.js +2683 -0
- package/dist/server/application/scheduled-task-service.d.ts +184 -0
- package/dist/server/application/scheduled-task-service.js +391 -0
- package/dist/server/application/session-orchestrator-service.d.ts +388 -0
- package/dist/server/application/session-orchestrator-service.js +1146 -0
- package/dist/server/application/session-reminder-service.d.ts +59 -0
- package/dist/server/application/session-reminder-service.js +141 -0
- package/dist/server/application/session-watchdog.d.ts +171 -0
- package/dist/server/application/session-watchdog.js +284 -0
- package/dist/server/application/workspace-service.d.ts +52 -0
- package/dist/server/application/workspace-service.js +186 -0
- package/dist/server/application/worktree-service.d.ts +13 -0
- package/dist/server/application/worktree-service.js +76 -0
- package/dist/server/browser-access.d.ts +34 -0
- package/dist/server/browser-access.js +89 -0
- package/dist/server/capability.d.ts +105 -0
- package/dist/server/capability.js +170 -0
- package/dist/server/command-handler.d.ts +93 -0
- package/dist/server/command-handler.js +540 -0
- package/dist/server/content-search.d.ts +16 -0
- package/dist/server/content-search.js +235 -0
- package/dist/server/conversation-usage.d.ts +22 -0
- package/dist/server/conversation-usage.js +43 -0
- package/dist/server/documents.d.ts +152 -0
- package/dist/server/documents.js +998 -0
- package/dist/server/engineering-learning.d.ts +30 -0
- package/dist/server/engineering-learning.js +106 -0
- package/dist/server/exec-service.d.ts +45 -0
- package/dist/server/exec-service.js +167 -0
- package/dist/server/explicit-file-open.d.ts +34 -0
- package/dist/server/explicit-file-open.js +105 -0
- package/dist/server/failure-text.d.ts +18 -0
- package/dist/server/failure-text.js +44 -0
- package/dist/server/feishu-cli.d.ts +223 -0
- package/dist/server/feishu-cli.js +464 -0
- package/dist/server/file-changes.d.ts +119 -0
- package/dist/server/file-changes.js +280 -0
- package/dist/server/file-diff.d.ts +41 -0
- package/dist/server/file-diff.js +97 -0
- package/dist/server/file-index.d.ts +100 -0
- package/dist/server/file-index.js +296 -0
- package/dist/server/file-name-index.d.ts +160 -0
- package/dist/server/file-name-index.js +411 -0
- package/dist/server/files.d.ts +269 -0
- package/dist/server/files.js +748 -0
- package/dist/server/git.d.ts +245 -0
- package/dist/server/git.js +903 -0
- package/dist/server/http-server.d.ts +45 -0
- package/dist/server/http-server.js +3830 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +485 -0
- package/dist/server/inline-thinking.d.ts +90 -0
- package/dist/server/inline-thinking.js +181 -0
- package/dist/server/json-comments.d.ts +14 -0
- package/dist/server/json-comments.js +71 -0
- package/dist/server/knowledge-embedding-worker.d.ts +1 -0
- package/dist/server/knowledge-embedding-worker.js +27 -0
- package/dist/server/knowledge-vectors.d.ts +150 -0
- package/dist/server/knowledge-vectors.js +385 -0
- package/dist/server/knowledge.d.ts +273 -0
- package/dist/server/knowledge.js +848 -0
- package/dist/server/length-continuation.d.ts +83 -0
- package/dist/server/length-continuation.js +118 -0
- package/dist/server/logging.d.ts +32 -0
- package/dist/server/logging.js +185 -0
- package/dist/server/managed-http-tunnel.d.ts +6 -0
- package/dist/server/managed-http-tunnel.js +85 -0
- package/dist/server/managed-http.d.ts +4 -0
- package/dist/server/managed-http.js +85 -0
- package/dist/server/managed-model-adapter.d.ts +17 -0
- package/dist/server/managed-model-adapter.js +75 -0
- package/dist/server/managed-model-gateway.d.ts +49 -0
- package/dist/server/managed-model-gateway.js +73 -0
- package/dist/server/managed-servers.d.ts +55 -0
- package/dist/server/managed-servers.js +396 -0
- package/dist/server/managed-ssh.d.ts +26 -0
- package/dist/server/managed-ssh.js +73 -0
- package/dist/server/manager-vault.d.ts +11 -0
- package/dist/server/manager-vault.js +67 -0
- package/dist/server/memory-recall.d.ts +25 -0
- package/dist/server/memory-recall.js +45 -0
- package/dist/server/memory.d.ts +67 -0
- package/dist/server/memory.js +216 -0
- package/dist/server/message-media.d.ts +7 -0
- package/dist/server/message-media.js +54 -0
- package/dist/server/model-context-window.d.ts +186 -0
- package/dist/server/model-context-window.js +444 -0
- package/dist/server/model-filter.d.ts +23 -0
- package/dist/server/model-filter.js +48 -0
- package/dist/server/models-store.d.ts +36 -0
- package/dist/server/models-store.js +132 -0
- package/dist/server/native-tool-settings.d.ts +25 -0
- package/dist/server/native-tool-settings.js +41 -0
- package/dist/server/native-tools-extension.d.ts +2 -0
- package/dist/server/native-tools-extension.js +39 -0
- package/dist/server/native-tools-service.d.ts +39 -0
- package/dist/server/native-tools-service.js +240 -0
- package/dist/server/persistence/app-state-repository.d.ts +65 -0
- package/dist/server/persistence/app-state-repository.js +1 -0
- package/dist/server/persistence/json-state-repository.d.ts +14 -0
- package/dist/server/persistence/json-state-repository.js +43 -0
- package/dist/server/persistence/open-state-store.d.ts +3 -0
- package/dist/server/persistence/open-state-store.js +35 -0
- package/dist/server/persistence/rename.d.ts +22 -0
- package/dist/server/persistence/rename.js +44 -0
- package/dist/server/persistence/sqlite-state-repository.d.ts +12 -0
- package/dist/server/persistence/sqlite-state-repository.js +264 -0
- package/dist/server/pi-command.d.ts +94 -0
- package/dist/server/pi-command.js +265 -0
- package/dist/server/pi-native.d.ts +12 -0
- package/dist/server/pi-native.js +16 -0
- package/dist/server/pi-session-events.d.ts +158 -0
- package/dist/server/pi-session-events.js +373 -0
- package/dist/server/pi-session-pool.d.ts +233 -0
- package/dist/server/pi-session-pool.js +382 -0
- package/dist/server/pi-session.d.ts +642 -0
- package/dist/server/pi-session.js +655 -0
- package/dist/server/presentations/schema.d.ts +120 -0
- package/dist/server/presentations/schema.js +128 -0
- package/dist/server/provider-network.d.ts +16 -0
- package/dist/server/provider-network.js +106 -0
- package/dist/server/provider-proxy.d.ts +18 -0
- package/dist/server/provider-proxy.js +200 -0
- package/dist/server/providers.d.ts +333 -0
- package/dist/server/providers.js +989 -0
- package/dist/server/remote-bootstrap.d.ts +17 -0
- package/dist/server/remote-bootstrap.js +119 -0
- package/dist/server/rpc-channel.d.ts +131 -0
- package/dist/server/rpc-channel.js +135 -0
- package/dist/server/runtime.d.ts +1393 -0
- package/dist/server/runtime.js +3286 -0
- package/dist/server/scheduled-tasks.d.ts +101 -0
- package/dist/server/scheduled-tasks.js +138 -0
- package/dist/server/server-context.d.ts +119 -0
- package/dist/server/server-context.js +1 -0
- package/dist/server/session-cwd.d.ts +19 -0
- package/dist/server/session-cwd.js +58 -0
- package/dist/server/session-ledger.d.ts +67 -0
- package/dist/server/session-ledger.js +76 -0
- package/dist/server/session-memory-scope.d.ts +4 -0
- package/dist/server/session-memory-scope.js +30 -0
- package/dist/server/session-repository.d.ts +100 -0
- package/dist/server/session-repository.js +246 -0
- package/dist/server/session-tree-scope.d.ts +125 -0
- package/dist/server/session-tree-scope.js +337 -0
- package/dist/server/skills.d.ts +23 -0
- package/dist/server/skills.js +190 -0
- package/dist/server/store.d.ts +1062 -0
- package/dist/server/store.js +3305 -0
- package/dist/server/subagent-runs.d.ts +185 -0
- package/dist/server/subagent-runs.js +383 -0
- package/dist/server/subagents.d.ts +200 -0
- package/dist/server/subagents.js +619 -0
- package/dist/server/task-tool.d.ts +282 -0
- package/dist/server/task-tool.js +507 -0
- package/dist/server/tavily.d.ts +32 -0
- package/dist/server/tavily.js +136 -0
- package/dist/server/team-context.d.ts +12 -0
- package/dist/server/team-context.js +180 -0
- package/dist/server/terminal.d.ts +163 -0
- package/dist/server/terminal.js +557 -0
- package/dist/server/thinking-level-discovery.d.ts +38 -0
- package/dist/server/thinking-level-discovery.js +183 -0
- package/dist/server/time-zone.d.ts +20 -0
- package/dist/server/time-zone.js +32 -0
- package/dist/server/tool-calls.d.ts +130 -0
- package/dist/server/tool-calls.js +341 -0
- package/dist/server/tool-llm.d.ts +72 -0
- package/dist/server/tool-llm.js +146 -0
- package/dist/server/tool-registry.d.ts +129 -0
- package/dist/server/tool-registry.js +249 -0
- package/dist/server/tool-runner.d.ts +112 -0
- package/dist/server/tool-runner.js +306 -0
- package/dist/server/turn-failure.d.ts +48 -0
- package/dist/server/turn-failure.js +148 -0
- package/dist/server/types.d.ts +2315 -0
- package/dist/server/types.js +11 -0
- package/dist/server/update-status.d.ts +14 -0
- package/dist/server/update-status.js +69 -0
- package/dist/server/update.d.ts +46 -0
- package/dist/server/update.js +104 -0
- package/dist/server/upload.d.ts +35 -0
- package/dist/server/upload.js +177 -0
- package/dist/server/version.d.ts +33 -0
- package/dist/server/version.js +111 -0
- package/dist/server/web.d.ts +27 -0
- package/dist/server/web.js +183 -0
- package/dist/server/workflow-engine.d.ts +47 -0
- package/dist/server/workflow-engine.js +255 -0
- package/dist/server/workflow.d.ts +329 -0
- package/dist/server/workflow.js +469 -0
- package/dist/server/workspace-file-indexes.d.ts +2 -0
- package/dist/server/workspace-file-indexes.js +61 -0
- package/dist/server/workspace-file-operations.d.ts +36 -0
- package/dist/server/workspace-file-operations.js +281 -0
- package/dist/server/workspace-file-response.d.ts +7 -0
- package/dist/server/workspace-file-response.js +79 -0
- package/dist/server/ws-server.d.ts +149 -0
- package/dist/server/ws-server.js +640 -0
- package/dist/shared/agent-order.d.ts +44 -0
- package/dist/shared/agent-order.js +50 -0
- package/dist/shared/archive-decisions.d.ts +44 -0
- package/dist/shared/archive-decisions.js +98 -0
- package/dist/shared/background-task.d.ts +25 -0
- package/dist/shared/background-task.js +183 -0
- package/dist/shared/child-session-lock.d.ts +37 -0
- package/dist/shared/child-session-lock.js +59 -0
- package/dist/shared/content-search.d.ts +22 -0
- package/dist/shared/content-search.js +1 -0
- package/dist/shared/conversation-title.d.ts +4 -0
- package/dist/shared/conversation-title.js +4 -0
- package/dist/shared/file-mentions.d.ts +17 -0
- package/dist/shared/file-mentions.js +91 -0
- package/dist/shared/git-commit.d.ts +11 -0
- package/dist/shared/git-commit.js +1 -0
- package/dist/shared/git-graph.d.ts +42 -0
- package/dist/shared/git-graph.js +30 -0
- package/dist/shared/group-chat.d.ts +132 -0
- package/dist/shared/group-chat.js +6 -0
- package/dist/shared/managed-servers.d.ts +36 -0
- package/dist/shared/managed-servers.js +1 -0
- package/dist/shared/message-media.d.ts +12 -0
- package/dist/shared/message-media.js +27 -0
- package/dist/shared/model-window-label.d.ts +39 -0
- package/dist/shared/model-window-label.js +55 -0
- package/dist/shared/native-tools.d.ts +43 -0
- package/dist/shared/native-tools.js +1 -0
- package/dist/shared/pi-cache-warming.d.ts +9 -0
- package/dist/shared/pi-cache-warming.js +4 -0
- package/dist/shared/project-overview.d.ts +107 -0
- package/dist/shared/project-overview.js +92 -0
- package/dist/shared/project-presentation.d.ts +55 -0
- package/dist/shared/project-presentation.js +111 -0
- package/dist/shared/provider-network.d.ts +30 -0
- package/dist/shared/provider-network.js +1 -0
- package/dist/shared/session-reporting.d.ts +40 -0
- package/dist/shared/session-reporting.js +97 -0
- package/dist/shared/session-search.d.ts +14 -0
- package/dist/shared/session-search.js +1 -0
- package/dist/shared/team-context-view.d.ts +33 -0
- package/dist/shared/team-context-view.js +49 -0
- package/dist/shared/team-context.d.ts +59 -0
- package/dist/shared/team-context.js +3 -0
- package/dist/shared/terminal-protocol.d.ts +71 -0
- package/dist/shared/terminal-protocol.js +1 -0
- package/dist/shared/thinking-levels.d.ts +53 -0
- package/dist/shared/thinking-levels.js +85 -0
- package/dist/shared/tool-glyph.d.ts +7 -0
- package/dist/shared/tool-glyph.js +19 -0
- package/dist/shared/transcript-order.d.ts +7 -0
- package/dist/shared/transcript-order.js +12 -0
- package/dist/shared/update-status.d.ts +28 -0
- package/dist/shared/update-status.js +1 -0
- package/dist/shared/workspace-file-preview.d.ts +4 -0
- package/dist/shared/workspace-file-preview.js +28 -0
- package/package.json +450 -4
- package/scripts/diagnose.mjs +603 -0
- package/scripts/patch-brace-expansion.mjs +260 -0
- package/scripts/restart-server.mjs +104 -0
- package/skills/presentation/SKILL.md +30 -0
- package/skills/presentation/references/data.md +10 -0
- package/skills/presentation/references/quality.md +12 -0
- package/skills/presentation/references/story.md +12 -0
- package/skills/presentation/references/templates-and-editing.md +11 -0
- package/skills/presentation/references/visual-system.md +10 -0
- package/skills/super-pi-agent-development/SKILL.md +25 -0
- package/skills/super-pi-development/SKILL.md +31 -0
- package/skills/super-pi-tool-development/SKILL.md +39 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Store } from "../store.js";
|
|
2
|
+
import type { DocumentFormat } from "../documents.js";
|
|
3
|
+
/**
|
|
4
|
+
* The largest request the document endpoint accepts.
|
|
5
|
+
*
|
|
6
|
+
* A document's extracted text rides in the request, so the cap is the document cap - a request past
|
|
7
|
+
* it is refused outright rather than truncated into a document that silently lost its tail.
|
|
8
|
+
*/
|
|
9
|
+
export declare const MAX_DOCUMENT_REQUEST_BYTES: number;
|
|
10
|
+
/**
|
|
11
|
+
* THE DOCUMENT SERVICE: what an agent can do with the files in a workspace.
|
|
12
|
+
*
|
|
13
|
+
* It is the agent-facing half of the parsing layer. The knowledge base uses the same parsing code
|
|
14
|
+
* (see `knowledge.ts`), so a PDF reads the same way whether it was imported into the knowledge base
|
|
15
|
+
* or read straight out of the workspace - which is the point of having one parsing layer.
|
|
16
|
+
*
|
|
17
|
+
* WHY THE SERVICE OWNS THE PATH GUARD AND NOT THE EXTENSION. The extension runs in Pi's process and
|
|
18
|
+
* could ask for any path it liked. The service resolves every path against the workspace root with
|
|
19
|
+
* the same `resolveInsideRoot` guard the file panel uses, so a `..` or a symlink pointing outside
|
|
20
|
+
* the workspace is refused by construction rather than by a check somebody has to remember.
|
|
21
|
+
*/
|
|
22
|
+
export declare class DocumentService {
|
|
23
|
+
private readonly store;
|
|
24
|
+
constructor(store: Store);
|
|
25
|
+
/**
|
|
26
|
+
* The workspace a conversation works in, taken from the store.
|
|
27
|
+
*
|
|
28
|
+
* The conversation is the caller's identity, and the workspace is derived from it. A request that
|
|
29
|
+
* named its own workspace would be a request that could read another workspace.
|
|
30
|
+
*/
|
|
31
|
+
private workspacePath;
|
|
32
|
+
/**
|
|
33
|
+
* Reads a file's contents.
|
|
34
|
+
*
|
|
35
|
+
* A text file is returned as it is; a document is parsed. The distinction matters because the two
|
|
36
|
+
* fail differently: a text file that does not exist is a missing file, while a document that
|
|
37
|
+
* cannot be parsed is a document with a reason.
|
|
38
|
+
*/
|
|
39
|
+
read(conversationId: string, path: string): Promise<{
|
|
40
|
+
text: string;
|
|
41
|
+
format: string;
|
|
42
|
+
warnings: string[];
|
|
43
|
+
etag: string;
|
|
44
|
+
}>;
|
|
45
|
+
/**
|
|
46
|
+
* Writes a document into the workspace.
|
|
47
|
+
*
|
|
48
|
+
* The content is Markdown for a Word or PDF document and CSV for a spreadsheet, and the format is
|
|
49
|
+
* taken from the file's extension - so the caller says "write this report to REPORT.docx" and the
|
|
50
|
+
* right writer is chosen. An extension that names no document format is refused, because writing
|
|
51
|
+
* a `.txt` file is what Pi's own `write` tool is for, and a second way to do it is a second way to
|
|
52
|
+
* be wrong about it.
|
|
53
|
+
*
|
|
54
|
+
* OVERWRITING AN EXISTING FILE NEEDS THE VERSION THE CALLER READ, the same rule the file panel's
|
|
55
|
+
* write enforces (docs/DOCUMENTS.md: 覆盖已有文件前要确认,etag 语义和文件面板一致). A document is a
|
|
56
|
+
* file a person edits; an agent told to "把这份报告改成正式版" would otherwise destroy a hand edit
|
|
57
|
+
* made an hour ago with no refusal, no diff, no warning. A missing etag over an existing file and a
|
|
58
|
+
* stale one are both refused, and the refusal carries the CURRENT etag - which is what makes an
|
|
59
|
+
* informed overwrite possible, the same way the panel's 409 does: re-sending the current etag is
|
|
60
|
+
* the deliberate "仍然覆盖", not a skipped check. A file that does not exist yet is the ordinary
|
|
61
|
+
* create case and needs no confirmation.
|
|
62
|
+
*/
|
|
63
|
+
write(conversationId: string, path: string, content: string, title?: string, baseEtag?: string): Promise<{
|
|
64
|
+
path: string;
|
|
65
|
+
bytes: number;
|
|
66
|
+
format: DocumentFormat;
|
|
67
|
+
}>;
|
|
68
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { mkdir, stat, writeFile } from "node:fs/promises";
|
|
2
|
+
import { dirname, extname } from "node:path";
|
|
3
|
+
import { buildDocument, documentFormatOf, DocumentError, extractText } from "../documents.js";
|
|
4
|
+
import { fileEtag, resolveInsideRoot } from "../files.js";
|
|
5
|
+
/**
|
|
6
|
+
* The largest request the document endpoint accepts.
|
|
7
|
+
*
|
|
8
|
+
* A document's extracted text rides in the request, so the cap is the document cap - a request past
|
|
9
|
+
* it is refused outright rather than truncated into a document that silently lost its tail.
|
|
10
|
+
*/
|
|
11
|
+
export const MAX_DOCUMENT_REQUEST_BYTES = 8 * 1024 * 1024;
|
|
12
|
+
/**
|
|
13
|
+
* THE DOCUMENT SERVICE: what an agent can do with the files in a workspace.
|
|
14
|
+
*
|
|
15
|
+
* It is the agent-facing half of the parsing layer. The knowledge base uses the same parsing code
|
|
16
|
+
* (see `knowledge.ts`), so a PDF reads the same way whether it was imported into the knowledge base
|
|
17
|
+
* or read straight out of the workspace - which is the point of having one parsing layer.
|
|
18
|
+
*
|
|
19
|
+
* WHY THE SERVICE OWNS THE PATH GUARD AND NOT THE EXTENSION. The extension runs in Pi's process and
|
|
20
|
+
* could ask for any path it liked. The service resolves every path against the workspace root with
|
|
21
|
+
* the same `resolveInsideRoot` guard the file panel uses, so a `..` or a symlink pointing outside
|
|
22
|
+
* the workspace is refused by construction rather than by a check somebody has to remember.
|
|
23
|
+
*/
|
|
24
|
+
export class DocumentService {
|
|
25
|
+
store;
|
|
26
|
+
constructor(store) {
|
|
27
|
+
this.store = store;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The workspace a conversation works in, taken from the store.
|
|
31
|
+
*
|
|
32
|
+
* The conversation is the caller's identity, and the workspace is derived from it. A request that
|
|
33
|
+
* named its own workspace would be a request that could read another workspace.
|
|
34
|
+
*/
|
|
35
|
+
workspacePath(conversationId) {
|
|
36
|
+
const conversation = this.store.snapshot().conversations.find(item => item.id === conversationId);
|
|
37
|
+
if (!conversation)
|
|
38
|
+
throw new Error("会话不存在");
|
|
39
|
+
const workspace = this.store.snapshot().workspaces.find(item => item.id === conversation.workspaceId);
|
|
40
|
+
if (!workspace)
|
|
41
|
+
throw new Error("工作区不存在");
|
|
42
|
+
return workspace.path;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Reads a file's contents.
|
|
46
|
+
*
|
|
47
|
+
* A text file is returned as it is; a document is parsed. The distinction matters because the two
|
|
48
|
+
* fail differently: a text file that does not exist is a missing file, while a document that
|
|
49
|
+
* cannot be parsed is a document with a reason.
|
|
50
|
+
*/
|
|
51
|
+
async read(conversationId, path) {
|
|
52
|
+
const root = this.workspacePath(conversationId);
|
|
53
|
+
const absolute = await resolveInsideRoot(root, path);
|
|
54
|
+
const info = await stat(absolute).catch(() => null);
|
|
55
|
+
if (!info || !info.isFile())
|
|
56
|
+
throw new Error(`找不到文件:${path}`);
|
|
57
|
+
const extension = extname(absolute).toLocaleLowerCase();
|
|
58
|
+
const format = documentFormatOf(extension);
|
|
59
|
+
if (format) {
|
|
60
|
+
try {
|
|
61
|
+
const extracted = await extractText(absolute, format);
|
|
62
|
+
return { text: extracted.text, format, warnings: extracted.warnings, etag: await fileEtag(absolute) };
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
// The parser's reasons are already written for a person - a scan with no text layer, an
|
|
66
|
+
// encrypted file, a missing package - and they are passed through unchanged. A model that
|
|
67
|
+
// is told "读取失败" cannot help the person; a model that is told "这份 PDF 是扫描件" can.
|
|
68
|
+
if (error instanceof DocumentError)
|
|
69
|
+
throw new Error(error.message);
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const { readFile } = await import("node:fs/promises");
|
|
74
|
+
const buffer = await readFile(absolute);
|
|
75
|
+
// The etag rides along so a follow-up `document_write` over this file can present the version it
|
|
76
|
+
// read - the same confirm-before-overwrite the file panel's editor lives by (see `write`).
|
|
77
|
+
return { text: buffer.toString("utf8"), format: extension || "text", warnings: [], etag: await fileEtag(absolute) };
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Writes a document into the workspace.
|
|
81
|
+
*
|
|
82
|
+
* The content is Markdown for a Word or PDF document and CSV for a spreadsheet, and the format is
|
|
83
|
+
* taken from the file's extension - so the caller says "write this report to REPORT.docx" and the
|
|
84
|
+
* right writer is chosen. An extension that names no document format is refused, because writing
|
|
85
|
+
* a `.txt` file is what Pi's own `write` tool is for, and a second way to do it is a second way to
|
|
86
|
+
* be wrong about it.
|
|
87
|
+
*
|
|
88
|
+
* OVERWRITING AN EXISTING FILE NEEDS THE VERSION THE CALLER READ, the same rule the file panel's
|
|
89
|
+
* write enforces (docs/DOCUMENTS.md: 覆盖已有文件前要确认,etag 语义和文件面板一致). A document is a
|
|
90
|
+
* file a person edits; an agent told to "把这份报告改成正式版" would otherwise destroy a hand edit
|
|
91
|
+
* made an hour ago with no refusal, no diff, no warning. A missing etag over an existing file and a
|
|
92
|
+
* stale one are both refused, and the refusal carries the CURRENT etag - which is what makes an
|
|
93
|
+
* informed overwrite possible, the same way the panel's 409 does: re-sending the current etag is
|
|
94
|
+
* the deliberate "仍然覆盖", not a skipped check. A file that does not exist yet is the ordinary
|
|
95
|
+
* create case and needs no confirmation.
|
|
96
|
+
*/
|
|
97
|
+
async write(conversationId, path, content, title, baseEtag) {
|
|
98
|
+
const root = this.workspacePath(conversationId);
|
|
99
|
+
const absolute = await resolveInsideRoot(root, path);
|
|
100
|
+
const extension = extname(absolute).toLocaleLowerCase();
|
|
101
|
+
const format = documentFormatOf(extension);
|
|
102
|
+
if (!format) {
|
|
103
|
+
throw new Error(`只能写 PDF、Word(.docx)和 Excel(.xlsx)文件;${extension || "这个文件"} 请用 write 工具直接写文本。`);
|
|
104
|
+
}
|
|
105
|
+
const existing = await stat(absolute).catch(() => null);
|
|
106
|
+
if (existing?.isFile()) {
|
|
107
|
+
const current = await fileEtag(absolute);
|
|
108
|
+
if (!baseEtag) {
|
|
109
|
+
throw new Error(`文件已存在:${path}。覆盖它必须先确认版本——先用 document_read 读取该文件,把它返回的 etag 作为 baseEtag 传入;当前 etag:${current}。`);
|
|
110
|
+
}
|
|
111
|
+
if (baseEtag !== current) {
|
|
112
|
+
throw new Error(`文件在磁盘上已被其他程序修改,未写入:${path}(当前 etag:${current},你提供的是 ${baseEtag})。如确认覆盖,请带着当前 etag 重试。`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const { bytes } = await buildDocument({ format, content, title });
|
|
116
|
+
await mkdir(dirname(absolute), { recursive: true });
|
|
117
|
+
await writeFile(absolute, bytes);
|
|
118
|
+
return { path, bytes: bytes.length, format };
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ExtensionUiHost } from "../runtime.js";
|
|
2
|
+
import type { ExtensionUiRequest, ExtensionUiAnswer, ExtensionUiCloseReason } from "../types.js";
|
|
3
|
+
import type { EventBroadcaster } from "../server-context.js";
|
|
4
|
+
/**
|
|
5
|
+
* Service managing extension UI interactive prompts between Pi / subagents and connected clients.
|
|
6
|
+
*
|
|
7
|
+
* NO SAFETY-NET TIMEOUT. A question that nobody answers stays in the map until the run it belongs to
|
|
8
|
+
* is stopped, the conversation is reset, or the server shuts down - the run-level teardown is the
|
|
9
|
+
* only path that ever settles an unanswered ask, and it is the right path: a model waiting on a
|
|
10
|
+
* human for ten minutes is not a model that has decided to give up, and resolving the ask with a
|
|
11
|
+
* fabricated "cancelled" answer was the source of 「未定义行为」 the user reported - the model
|
|
12
|
+
* accepted the cancel and continued from a state that was not the state the person was supposed to
|
|
13
|
+
* produce. A living, unanswered question is honest; a timed-out one is fiction.
|
|
14
|
+
*/
|
|
15
|
+
export declare class ExtensionUiService {
|
|
16
|
+
private readonly broadcaster;
|
|
17
|
+
private readonly canAddressUser;
|
|
18
|
+
private readonly pendingUi;
|
|
19
|
+
private readonly view;
|
|
20
|
+
snapshot(visible: Set<string>): {
|
|
21
|
+
conversationId: string;
|
|
22
|
+
request: ExtensionUiRequest;
|
|
23
|
+
}[];
|
|
24
|
+
constructor(broadcaster: EventBroadcaster, canAddressUser?: (conversationId: string) => boolean);
|
|
25
|
+
private uiKey;
|
|
26
|
+
/**
|
|
27
|
+
* Settles a pending UI request by answering, timing out, or aborting.
|
|
28
|
+
*/
|
|
29
|
+
settleUi(key: string, answer: ExtensionUiAnswer, reason: ExtensionUiCloseReason): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Responds to an extension UI question from the client.
|
|
32
|
+
*/
|
|
33
|
+
answerUi(conversationId: string, requestId: string, answer: ExtensionUiAnswer): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Cancels any pending UI requests for a given conversation.
|
|
36
|
+
*/
|
|
37
|
+
cancelPendingUi(conversationId: string, reason: ExtensionUiCloseReason, owner?: {
|
|
38
|
+
runId?: string;
|
|
39
|
+
}): void;
|
|
40
|
+
/**
|
|
41
|
+
* Creates an ExtensionUiHost interface for a conversation or subagent run.
|
|
42
|
+
*/
|
|
43
|
+
createHost(conversationId: string, runId?: string): ExtensionUiHost;
|
|
44
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service managing extension UI interactive prompts between Pi / subagents and connected clients.
|
|
3
|
+
*
|
|
4
|
+
* NO SAFETY-NET TIMEOUT. A question that nobody answers stays in the map until the run it belongs to
|
|
5
|
+
* is stopped, the conversation is reset, or the server shuts down - the run-level teardown is the
|
|
6
|
+
* only path that ever settles an unanswered ask, and it is the right path: a model waiting on a
|
|
7
|
+
* human for ten minutes is not a model that has decided to give up, and resolving the ask with a
|
|
8
|
+
* fabricated "cancelled" answer was the source of 「未定义行为」 the user reported - the model
|
|
9
|
+
* accepted the cancel and continued from a state that was not the state the person was supposed to
|
|
10
|
+
* produce. A living, unanswered question is honest; a timed-out one is fiction.
|
|
11
|
+
*/
|
|
12
|
+
export class ExtensionUiService {
|
|
13
|
+
broadcaster;
|
|
14
|
+
canAddressUser;
|
|
15
|
+
pendingUi = new Map();
|
|
16
|
+
view = new Map();
|
|
17
|
+
snapshot(visible) {
|
|
18
|
+
const pending = [...this.pendingUi.values()].filter(item => visible.has(item.conversationId))
|
|
19
|
+
.map(({ conversationId, request }) => ({ conversationId, request }));
|
|
20
|
+
for (const [conversationId, requests] of this.view) {
|
|
21
|
+
if (visible.has(conversationId))
|
|
22
|
+
for (const { request } of requests.values())
|
|
23
|
+
pending.push({ conversationId, request });
|
|
24
|
+
}
|
|
25
|
+
return pending;
|
|
26
|
+
}
|
|
27
|
+
constructor(broadcaster, canAddressUser = () => true) {
|
|
28
|
+
this.broadcaster = broadcaster;
|
|
29
|
+
this.canAddressUser = canAddressUser;
|
|
30
|
+
}
|
|
31
|
+
uiKey(conversationId, requestId) {
|
|
32
|
+
return `${conversationId}\u0000${requestId}`;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Settles a pending UI request by answering, timing out, or aborting.
|
|
36
|
+
*/
|
|
37
|
+
settleUi(key, answer, reason) {
|
|
38
|
+
const pending = this.pendingUi.get(key);
|
|
39
|
+
if (!pending) {
|
|
40
|
+
console.warn(`Super Pi: Extension UI answer for ${key.replace("\u0000", "/")} arrived after that request was already closed - ignored, no second reply sent.`);
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
this.pendingUi.delete(key);
|
|
44
|
+
if (pending.timer)
|
|
45
|
+
clearTimeout(pending.timer);
|
|
46
|
+
pending.resolve(answer);
|
|
47
|
+
this.broadcaster.broadcast({
|
|
48
|
+
type: "extension.ui.closed",
|
|
49
|
+
conversationId: pending.conversationId,
|
|
50
|
+
requestId: pending.request.requestId,
|
|
51
|
+
reason,
|
|
52
|
+
});
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Responds to an extension UI question from the client.
|
|
57
|
+
*/
|
|
58
|
+
answerUi(conversationId, requestId, answer) {
|
|
59
|
+
return this.settleUi(this.uiKey(conversationId, requestId), answer, answer.cancelled ? "cancelled" : "answered");
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Cancels any pending UI requests for a given conversation.
|
|
63
|
+
*/
|
|
64
|
+
cancelPendingUi(conversationId, reason, owner) {
|
|
65
|
+
let cleared = false;
|
|
66
|
+
if (reason !== "expired") {
|
|
67
|
+
const view = this.view.get(conversationId);
|
|
68
|
+
if (!owner)
|
|
69
|
+
cleared = this.view.delete(conversationId);
|
|
70
|
+
else if (view) {
|
|
71
|
+
for (const [key, item] of view) {
|
|
72
|
+
if (item.runId === owner.runId)
|
|
73
|
+
cleared = view.delete(key) || cleared;
|
|
74
|
+
}
|
|
75
|
+
if (!view.size)
|
|
76
|
+
this.view.delete(conversationId);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
for (const [key, pending] of [...this.pendingUi]) {
|
|
80
|
+
if (pending.conversationId === conversationId && (!owner || pending.runId === owner.runId)) {
|
|
81
|
+
this.settleUi(key, { cancelled: true }, reason);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (cleared)
|
|
85
|
+
this.broadcaster.broadcastState?.();
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Creates an ExtensionUiHost interface for a conversation or subagent run.
|
|
89
|
+
*/
|
|
90
|
+
createHost(conversationId, runId) {
|
|
91
|
+
const scoped = (request) => runId ? { ...request, requestId: `${runId}:${request.requestId}` } : request;
|
|
92
|
+
return {
|
|
93
|
+
notify: (request) => {
|
|
94
|
+
if (!this.canAddressUser(conversationId))
|
|
95
|
+
return;
|
|
96
|
+
const shown = scoped(request);
|
|
97
|
+
if (request.method === "setStatus" || request.method === "setWidget" || request.method === "setTitle") {
|
|
98
|
+
const key = JSON.stringify([runId ?? null, request.method, request.statusKey ?? request.widgetKey ?? ""]);
|
|
99
|
+
const view = this.view.get(conversationId) ?? new Map();
|
|
100
|
+
if ((request.method === "setStatus" && request.statusText === undefined)
|
|
101
|
+
|| (request.method === "setWidget" && request.widgetLines === undefined)
|
|
102
|
+
|| (request.method === "setTitle" && !request.title))
|
|
103
|
+
view.delete(key);
|
|
104
|
+
else
|
|
105
|
+
view.set(key, { request: shown, runId });
|
|
106
|
+
if (view.size)
|
|
107
|
+
this.view.set(conversationId, view);
|
|
108
|
+
else
|
|
109
|
+
this.view.delete(conversationId);
|
|
110
|
+
}
|
|
111
|
+
this.broadcaster.broadcast({ type: "extension.ui", conversationId, request: shown });
|
|
112
|
+
},
|
|
113
|
+
ask: async (request) => {
|
|
114
|
+
if (!this.canAddressUser(conversationId))
|
|
115
|
+
return { cancelled: true };
|
|
116
|
+
return new Promise((resolve) => {
|
|
117
|
+
const shown = scoped(request.timeoutMs === undefined ? request : { ...request, deadlineAt: Date.now() + request.timeoutMs });
|
|
118
|
+
const key = this.uiKey(conversationId, shown.requestId);
|
|
119
|
+
// Only the Pi-declared `timeoutMs` is honoured. There is no safety net when Pi did not set
|
|
120
|
+
// one: a question Pi chose to leave open is a question the model is waiting on, and a
|
|
121
|
+
// fabricated cancel would be the model continuing on a false premise. The run-level
|
|
122
|
+
// teardown (stop / abort / shutdown) is the path that closes an unanswered ask.
|
|
123
|
+
const pending = { conversationId, runId, request: shown, resolve };
|
|
124
|
+
if (shown.timeoutMs !== undefined) {
|
|
125
|
+
pending.timer = setTimeout(() => {
|
|
126
|
+
this.settleUi(key, { cancelled: true }, "timeout");
|
|
127
|
+
}, shown.timeoutMs);
|
|
128
|
+
}
|
|
129
|
+
this.pendingUi.set(key, pending);
|
|
130
|
+
this.broadcaster.broadcast({ type: "extension.ui", conversationId, request: shown });
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { FeishuCli } from "../feishu-cli.js";
|
|
2
|
+
/**
|
|
3
|
+
* The largest request the Feishu endpoint accepts.
|
|
4
|
+
*
|
|
5
|
+
* The Markdown of a document rides in the request body, so the cap is generous for a document and
|
|
6
|
+
* small enough that a runaway paste is refused rather than accepted.
|
|
7
|
+
*/
|
|
8
|
+
export declare const MAX_FEISHU_REQUEST_BYTES: number;
|
|
9
|
+
/**
|
|
10
|
+
* WHAT THE PANEL NEEDS TO SHOW, in words a person can act on.
|
|
11
|
+
*/
|
|
12
|
+
export type FeishuStatus = {
|
|
13
|
+
/** Whether the official CLI is on this machine at all. */
|
|
14
|
+
installed: boolean;
|
|
15
|
+
version?: string;
|
|
16
|
+
/** The application the CLI is configured with, when it has one. */
|
|
17
|
+
appId?: string;
|
|
18
|
+
/** Whether a person has authorized the CLI to act as them. */
|
|
19
|
+
userReady: boolean;
|
|
20
|
+
/** Whether the CLI can act as the application itself. */
|
|
21
|
+
botReady: boolean;
|
|
22
|
+
/** The identity the CLI will use by default. */
|
|
23
|
+
identity?: "user" | "bot";
|
|
24
|
+
/** Whether the agent can read and write documents right now. */
|
|
25
|
+
connected: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* WHICH STEP OF THE GUIDE THE PERSON IS ON.
|
|
28
|
+
*
|
|
29
|
+
* 1 = install the CLI, 2 = connect the account, 3 = ready. The panel draws the three steps and
|
|
30
|
+
* marks this one, so "what do I do now" is answered by where the cursor is rather than by a
|
|
31
|
+
* sentence the person has to interpret.
|
|
32
|
+
*/
|
|
33
|
+
step: 1 | 2 | 3;
|
|
34
|
+
/** What to do next, in one sentence. */
|
|
35
|
+
message: string;
|
|
36
|
+
/** The CLI's own words, when it had something to say about the situation. */
|
|
37
|
+
detail?: string;
|
|
38
|
+
/** The CLI's own hint, which usually names the exact command to run. */
|
|
39
|
+
hint?: string;
|
|
40
|
+
/** Whether the check actually reached Feishu. */
|
|
41
|
+
verified?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* WHETHER THE APPLICATION ITSELF HAS TO BE REBUILT.
|
|
44
|
+
*
|
|
45
|
+
* Distinct from "step 2": a person whose application is fine but who has not logged in still
|
|
46
|
+
* needs step 2, while a person whose credential was refused needs a NEW application. Telling
|
|
47
|
+
* those two apart is what keeps a transient network failure from being answered by "let me
|
|
48
|
+
* create you another application".
|
|
49
|
+
*/
|
|
50
|
+
rebuild?: boolean;
|
|
51
|
+
};
|
|
52
|
+
/** The outcome of starting the connect flow. */
|
|
53
|
+
export type FeishuConnectResult = {
|
|
54
|
+
ok: boolean;
|
|
55
|
+
/** Which step the person is on: creating an application, or authorizing their account. */
|
|
56
|
+
step?: "app" | "login";
|
|
57
|
+
/** The URL to open in a browser. */
|
|
58
|
+
verificationUri?: string;
|
|
59
|
+
/** The device code, kept server-side until the person says they are done. */
|
|
60
|
+
deviceCode?: string;
|
|
61
|
+
message: string;
|
|
62
|
+
/** Feishu's own "what to do about it", when there was one. */
|
|
63
|
+
hint?: string;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* THE FEISHU SERVICE: what an agent can do with the cloud documents of a Feishu enterprise.
|
|
67
|
+
*
|
|
68
|
+
* IT OWNS NO CREDENTIAL. The official CLI owns them, in the OS keychain, and this service only
|
|
69
|
+
* runs commands. That is the whole point of going through the CLI: Super Pi never sees an App
|
|
70
|
+
* Secret, never sees a user token, and never writes a credential file to disk.
|
|
71
|
+
*/
|
|
72
|
+
export declare class FeishuService {
|
|
73
|
+
private readonly cli;
|
|
74
|
+
/** The device code of a login that is waiting for the person to authorize it. */
|
|
75
|
+
private pendingDeviceCode?;
|
|
76
|
+
/** Whether an application registration is running and waiting for the browser confirmation. */
|
|
77
|
+
private pendingAppCreation;
|
|
78
|
+
constructor(cli?: FeishuCli);
|
|
79
|
+
/**
|
|
80
|
+
* WHAT THE CLI CAN DO RIGHT NOW.
|
|
81
|
+
*
|
|
82
|
+
* The states a person can be in, and what each one means for the agent:
|
|
83
|
+
*
|
|
84
|
+
* - The CLI is not installed: nothing works, and the fix is one command.
|
|
85
|
+
* - The CLI has no application: `config init --new` creates one through a browser confirmation,
|
|
86
|
+
* so the developer console is never visited.
|
|
87
|
+
* - The application exists but its credential is no longer accepted: the CLI says
|
|
88
|
+
* `verify_failed` and names the reason, and the fix is a new application - which is the same
|
|
89
|
+
* browser confirmation, so it stays one button.
|
|
90
|
+
* - The application works but no person is logged in: the agent can act as the application, but
|
|
91
|
+
* it cannot reach that person's own documents until they authorize it.
|
|
92
|
+
*/
|
|
93
|
+
status(): Promise<FeishuStatus>;
|
|
94
|
+
/**
|
|
95
|
+
* CHECKS THE CONNECTION, and says whether it actually works.
|
|
96
|
+
*
|
|
97
|
+
* The status already verifies; this is the same answer shaped for a button, so that a person can
|
|
98
|
+
* ask "it still doesn't work, why?" and get the CLI's own verdict rather than a guess.
|
|
99
|
+
*/
|
|
100
|
+
verify(): Promise<{
|
|
101
|
+
ok: boolean;
|
|
102
|
+
message: string;
|
|
103
|
+
detail?: string;
|
|
104
|
+
hint?: string;
|
|
105
|
+
}>;
|
|
106
|
+
/**
|
|
107
|
+
* STARTS THE CONNECT FLOW.
|
|
108
|
+
*
|
|
109
|
+
* Two steps, and which one runs is decided by what the CLI already has:
|
|
110
|
+
*
|
|
111
|
+
* - No application, or one whose credential no longer works: `config init --new` registers a
|
|
112
|
+
* fresh application through a browser confirmation. It BLOCKS until the person confirms, so it
|
|
113
|
+
* runs in the background and the URL is taken from its output. The broken case goes here too,
|
|
114
|
+
* because a new application is the one repair that needs no secret to be typed into a form.
|
|
115
|
+
* - A working application but no person: `auth login --no-wait --json` asks for a device code
|
|
116
|
+
* and hands back the URL to open. The code is kept here until the person says they are done.
|
|
117
|
+
*/
|
|
118
|
+
connect(): Promise<FeishuConnectResult>;
|
|
119
|
+
/**
|
|
120
|
+
* FINISHES THE FLOW, once the person says they are done.
|
|
121
|
+
*
|
|
122
|
+
* TWO KINDS OF "DONE", and the difference is what the CLI is waiting for:
|
|
123
|
+
*
|
|
124
|
+
* - An application is being registered: `config init --new` finishes by itself once the person
|
|
125
|
+
* confirms in the browser, so there is nothing to hand back. The status is re-read and the
|
|
126
|
+
* answer is whether the application showed up.
|
|
127
|
+
* - A login is being authorized: the device code is handed back to the CLI, which completes the
|
|
128
|
+
* exchange and stores the token in the keychain. Super Pi never sees the token itself.
|
|
129
|
+
*/
|
|
130
|
+
completeConnect(): Promise<FeishuConnectResult>;
|
|
131
|
+
/**
|
|
132
|
+
* READS A DOCUMENT.
|
|
133
|
+
*
|
|
134
|
+
* The CLI resolves a knowledge-base link itself, so a `/wiki/` URL is passed through untouched -
|
|
135
|
+
* and it answers with Markdown, which is the shape a model wants.
|
|
136
|
+
*/
|
|
137
|
+
read(input: {
|
|
138
|
+
url: string;
|
|
139
|
+
}): Promise<{
|
|
140
|
+
documentId?: string;
|
|
141
|
+
revisionId?: number;
|
|
142
|
+
title?: string;
|
|
143
|
+
url: string;
|
|
144
|
+
format: "markdown";
|
|
145
|
+
content: string;
|
|
146
|
+
}>;
|
|
147
|
+
/**
|
|
148
|
+
* WRITES A DOCUMENT.
|
|
149
|
+
*
|
|
150
|
+
* THREE MODES, and the difference between them is who decides what survives:
|
|
151
|
+
*
|
|
152
|
+
* - `create` makes a new document. Nothing can be lost, because nothing was there.
|
|
153
|
+
* - `append` adds to the end. Nothing can be lost either.
|
|
154
|
+
* - `replace` replaces the whole document. This one CAN lose a person's work, so it needs the
|
|
155
|
+
* revision the caller read - the same rule the file panel's write lives by, and for the same
|
|
156
|
+
* reason: an agent told to "把这份报告改成正式版" would otherwise destroy a hand edit made an
|
|
157
|
+
* hour ago, with no refusal and no warning.
|
|
158
|
+
*
|
|
159
|
+
* THE REVISION IS THE ETAG. The CLI passes it as the base revision of the edit, and Feishu
|
|
160
|
+
* refuses the edit when the document has moved on - so the check is enforced by the API rather
|
|
161
|
+
* than by a comparison Super Pi makes and then has to keep honest.
|
|
162
|
+
*/
|
|
163
|
+
write(input: {
|
|
164
|
+
url?: string;
|
|
165
|
+
content: string;
|
|
166
|
+
mode?: "create" | "append" | "replace";
|
|
167
|
+
title?: string;
|
|
168
|
+
baseRevisionId?: string;
|
|
169
|
+
}): Promise<{
|
|
170
|
+
documentId?: string;
|
|
171
|
+
revisionId?: number;
|
|
172
|
+
url?: string;
|
|
173
|
+
mode: "create" | "append" | "replace";
|
|
174
|
+
}>;
|
|
175
|
+
/**
|
|
176
|
+
* THE TOOL CALL, as the extension sends it.
|
|
177
|
+
*/
|
|
178
|
+
tool(body: unknown): Promise<unknown>;
|
|
179
|
+
}
|