co-maintainer 0.4.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +105 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +9 -0
- package/dist/mod.d.ts +4 -0
- package/dist/mod.js +2 -0
- package/dist/package.json +54 -0
- package/dist/src/ai/batch.d.ts +16 -0
- package/dist/src/ai/batch.js +117 -0
- package/dist/src/ai/fake.d.ts +7 -0
- package/dist/src/ai/fake.js +40 -0
- package/dist/src/ai/hetzner.d.ts +16 -0
- package/dist/src/ai/hetzner.js +69 -0
- package/dist/src/ai/mermaid.d.ts +27 -0
- package/dist/src/ai/mermaid.js +457 -0
- package/dist/src/ai/mermaid_loop.d.ts +12 -0
- package/dist/src/ai/mermaid_loop.js +100 -0
- package/dist/src/ai/openrouter.d.ts +9 -0
- package/dist/src/ai/openrouter.js +29 -0
- package/dist/src/ai/provider.d.ts +4 -0
- package/dist/src/ai/provider.js +63 -0
- package/dist/src/cli/args.d.ts +5 -0
- package/dist/src/cli/args.js +252 -0
- package/dist/src/cli/commands/probe.d.ts +2 -0
- package/dist/src/cli/commands/probe.js +122 -0
- package/dist/src/cli/commands/review.d.ts +3 -0
- package/dist/src/cli/commands/review.js +84 -0
- package/dist/src/cli/commands/serve.d.ts +18 -0
- package/dist/src/cli/commands/serve.js +183 -0
- package/dist/src/cli/commands/set.d.ts +7 -0
- package/dist/src/cli/commands/set.js +171 -0
- package/dist/src/cli/main.d.ts +1 -0
- package/dist/src/cli/main.js +27 -0
- package/dist/src/cli/prompt.d.ts +4 -0
- package/dist/src/cli/prompt.js +26 -0
- package/dist/src/cli/review_args.d.ts +28 -0
- package/dist/src/cli/review_args.js +84 -0
- package/dist/src/cli/review_output.d.ts +2 -0
- package/dist/src/cli/review_output.js +10 -0
- package/dist/src/cli/review_result.d.ts +81 -0
- package/dist/src/cli/review_result.js +281 -0
- package/dist/src/config.d.ts +108 -0
- package/dist/src/config.js +138 -0
- package/dist/src/git/default_branch.d.ts +5 -0
- package/dist/src/git/default_branch.js +22 -0
- package/dist/src/github/app.d.ts +43 -0
- package/dist/src/github/app.js +120 -0
- package/dist/src/github/client.d.ts +17 -0
- package/dist/src/github/client.js +66 -0
- package/dist/src/github/collect.d.ts +7 -0
- package/dist/src/github/collect.js +368 -0
- package/dist/src/github/gh.d.ts +8 -0
- package/dist/src/github/gh.js +63 -0
- package/dist/src/github/jwt.d.ts +12 -0
- package/dist/src/github/jwt.js +84 -0
- package/dist/src/github/oauth.d.ts +9 -0
- package/dist/src/github/oauth.js +51 -0
- package/dist/src/github/pat.d.ts +10 -0
- package/dist/src/github/pat.js +60 -0
- package/dist/src/knowledge/facts.d.ts +3 -0
- package/dist/src/knowledge/facts.js +325 -0
- package/dist/src/knowledge/guide.d.ts +6 -0
- package/dist/src/knowledge/guide.js +82 -0
- package/dist/src/knowledge/probe.d.ts +12 -0
- package/dist/src/knowledge/probe.js +144 -0
- package/dist/src/knowledge/sections.d.ts +2 -0
- package/dist/src/knowledge/sections.js +13 -0
- package/dist/src/knowledge/skill.d.ts +10 -0
- package/dist/src/knowledge/skill.js +106 -0
- package/dist/src/knowledge/synthesis.d.ts +7 -0
- package/dist/src/knowledge/synthesis.js +315 -0
- package/dist/src/knowledge/types.d.ts +49 -0
- package/dist/src/knowledge/types.js +1 -0
- package/dist/src/knowledge/validate.d.ts +6 -0
- package/dist/src/knowledge/validate.js +134 -0
- package/dist/src/local/carry_over_store.d.ts +18 -0
- package/dist/src/local/carry_over_store.js +40 -0
- package/dist/src/local/codegraph_exclude.d.ts +3 -0
- package/dist/src/local/codegraph_exclude.js +26 -0
- package/dist/src/local/codegraph_prepare.d.ts +17 -0
- package/dist/src/local/codegraph_prepare.js +51 -0
- package/dist/src/local/git_ops.d.ts +12 -0
- package/dist/src/local/git_ops.js +98 -0
- package/dist/src/local/git_parse.d.ts +27 -0
- package/dist/src/local/git_parse.js +131 -0
- package/dist/src/local/git_revision.d.ts +15 -0
- package/dist/src/local/git_revision.js +141 -0
- package/dist/src/local/git_untracked.d.ts +21 -0
- package/dist/src/local/git_untracked.js +79 -0
- package/dist/src/local/review_local.d.ts +4 -0
- package/dist/src/local/review_local.js +273 -0
- package/dist/src/local/review_lock.d.ts +7 -0
- package/dist/src/local/review_lock.js +45 -0
- package/dist/src/pr/checkout.d.ts +25 -0
- package/dist/src/pr/checkout.js +136 -0
- package/dist/src/pr/codegraph_tool_args.d.ts +8 -0
- package/dist/src/pr/codegraph_tool_args.js +34 -0
- package/dist/src/pr/codegraph_tools.d.ts +15 -0
- package/dist/src/pr/codegraph_tools.js +408 -0
- package/dist/src/pr/diff_summary.d.ts +6 -0
- package/dist/src/pr/diff_summary.js +52 -0
- package/dist/src/pr/findings.d.ts +14 -0
- package/dist/src/pr/findings.js +94 -0
- package/dist/src/pr/github_revision.d.ts +4 -0
- package/dist/src/pr/github_revision.js +39 -0
- package/dist/src/pr/hunks.d.ts +18 -0
- package/dist/src/pr/hunks.js +73 -0
- package/dist/src/pr/reviewer.d.ts +40 -0
- package/dist/src/pr/reviewer.js +582 -0
- package/dist/src/pr/rounds.d.ts +17 -0
- package/dist/src/pr/rounds.js +43 -0
- package/dist/src/pr/scope.d.ts +35 -0
- package/dist/src/pr/scope.js +84 -0
- package/dist/src/pr/snapshot.d.ts +11 -0
- package/dist/src/pr/snapshot.js +1 -0
- package/dist/src/pr/suggestion.d.ts +17 -0
- package/dist/src/pr/suggestion.js +70 -0
- package/dist/src/remote/client.d.ts +4 -0
- package/dist/src/remote/client.js +199 -0
- package/dist/src/remote/client_tools.d.ts +13 -0
- package/dist/src/remote/client_tools.js +30 -0
- package/dist/src/remote/fixtures.d.ts +1 -0
- package/dist/src/remote/fixtures.js +30 -0
- package/dist/src/remote/revision_from_submit.d.ts +2 -0
- package/dist/src/remote/revision_from_submit.js +26 -0
- package/dist/src/remote/schema.d.ts +14 -0
- package/dist/src/remote/schema.js +30 -0
- package/dist/src/remote/server/body.d.ts +18 -0
- package/dist/src/remote/server/body.js +73 -0
- package/dist/src/remote/server/routes.d.ts +1 -0
- package/dist/src/remote/server/routes.js +150 -0
- package/dist/src/remote/server/sessions.d.ts +16 -0
- package/dist/src/remote/server/sessions.js +48 -0
- package/dist/src/remote/server/sync.d.ts +3 -0
- package/dist/src/remote/server/sync.js +90 -0
- package/dist/src/remote/tool_bridge.d.ts +15 -0
- package/dist/src/remote/tool_bridge.js +84 -0
- package/dist/src/remote/validate.d.ts +8 -0
- package/dist/src/remote/validate.js +248 -0
- package/dist/src/review/carry_over.d.ts +63 -0
- package/dist/src/review/carry_over.js +372 -0
- package/dist/src/review/engine.d.ts +13 -0
- package/dist/src/review/engine.js +4 -0
- package/dist/src/review/guides.d.ts +12 -0
- package/dist/src/review/guides.js +44 -0
- package/dist/src/review/revision.d.ts +26 -0
- package/dist/src/review/revision.js +57 -0
- package/dist/src/server/api/activity.d.ts +1 -0
- package/dist/src/server/api/activity.js +12 -0
- package/dist/src/server/api/analytics.d.ts +1 -0
- package/dist/src/server/api/analytics.js +9 -0
- package/dist/src/server/api/installations.d.ts +4 -0
- package/dist/src/server/api/installations.js +24 -0
- package/dist/src/server/api/jobs.d.ts +1 -0
- package/dist/src/server/api/jobs.js +86 -0
- package/dist/src/server/api/json_body.d.ts +1 -0
- package/dist/src/server/api/json_body.js +14 -0
- package/dist/src/server/api/remote_tokens.d.ts +1 -0
- package/dist/src/server/api/remote_tokens.js +71 -0
- package/dist/src/server/api/repos.d.ts +4 -0
- package/dist/src/server/api/repos.js +136 -0
- package/dist/src/server/api/settings.d.ts +1 -0
- package/dist/src/server/api/settings.js +210 -0
- package/dist/src/server/app.d.ts +27 -0
- package/dist/src/server/app.js +147 -0
- package/dist/src/server/assets.d.ts +3 -0
- package/dist/src/server/assets.js +21 -0
- package/dist/src/server/auth.d.ts +44 -0
- package/dist/src/server/auth.js +188 -0
- package/dist/src/server/errors.d.ts +8 -0
- package/dist/src/server/errors.js +10 -0
- package/dist/src/server/http.d.ts +8 -0
- package/dist/src/server/http.js +117 -0
- package/dist/src/server/logo.d.ts +1 -0
- package/dist/src/server/logo.js +2 -0
- package/dist/src/server/pages/activity.d.ts +4 -0
- package/dist/src/server/pages/activity.js +200 -0
- package/dist/src/server/pages/add_repo.d.ts +9 -0
- package/dist/src/server/pages/add_repo.js +56 -0
- package/dist/src/server/pages/analytics.d.ts +2 -0
- package/dist/src/server/pages/analytics.js +193 -0
- package/dist/src/server/pages/client.d.ts +2 -0
- package/dist/src/server/pages/client.js +2 -0
- package/dist/src/server/pages/home.d.ts +16 -0
- package/dist/src/server/pages/home.js +87 -0
- package/dist/src/server/pages/knowledge.d.ts +2 -0
- package/dist/src/server/pages/knowledge.js +64 -0
- package/dist/src/server/pages/layout.d.ts +32 -0
- package/dist/src/server/pages/layout.js +230 -0
- package/dist/src/server/pages/pr.d.ts +2 -0
- package/dist/src/server/pages/pr.js +109 -0
- package/dist/src/server/pages/repo.d.ts +2 -0
- package/dist/src/server/pages/repo.js +92 -0
- package/dist/src/server/pages/repo_prs.d.ts +2 -0
- package/dist/src/server/pages/repo_prs.js +75 -0
- package/dist/src/server/pages/repo_remote.d.ts +2 -0
- package/dist/src/server/pages/repo_remote.js +38 -0
- package/dist/src/server/pages/repo_settings.d.ts +3 -0
- package/dist/src/server/pages/repo_settings.js +127 -0
- package/dist/src/server/pages/router.d.ts +17 -0
- package/dist/src/server/pages/router.js +312 -0
- package/dist/src/server/pages/settings.d.ts +2 -0
- package/dist/src/server/pages/settings.js +337 -0
- package/dist/src/server/pages/setup.d.ts +5 -0
- package/dist/src/server/pages/setup.js +38 -0
- package/dist/src/server/pages/styles.d.ts +2 -0
- package/dist/src/server/pages/styles.js +2 -0
- package/dist/src/server/webhook/index.d.ts +1 -0
- package/dist/src/server/webhook/index.js +64 -0
- package/dist/src/server/webhook/signature.d.ts +7 -0
- package/dist/src/server/webhook/signature.js +41 -0
- package/dist/src/services/credentials.d.ts +19 -0
- package/dist/src/services/credentials.js +146 -0
- package/dist/src/services/dashboard.d.ts +165 -0
- package/dist/src/services/dashboard.js +200 -0
- package/dist/src/services/drift.d.ts +13 -0
- package/dist/src/services/drift.js +76 -0
- package/dist/src/services/jobs.d.ts +34 -0
- package/dist/src/services/jobs.js +222 -0
- package/dist/src/services/remote_review.d.ts +10 -0
- package/dist/src/services/remote_review.js +274 -0
- package/dist/src/services/remote_review_abort.d.ts +3 -0
- package/dist/src/services/remote_review_abort.js +11 -0
- package/dist/src/services/remote_token_jobs.d.ts +1 -0
- package/dist/src/services/remote_token_jobs.js +20 -0
- package/dist/src/services/remote_tokens.d.ts +13 -0
- package/dist/src/services/remote_tokens.js +57 -0
- package/dist/src/services/replies.d.ts +7 -0
- package/dist/src/services/replies.js +248 -0
- package/dist/src/services/review.d.ts +35 -0
- package/dist/src/services/review.js +671 -0
- package/dist/src/services/setup.d.ts +29 -0
- package/dist/src/services/setup.js +364 -0
- package/dist/src/services/webhook.d.ts +22 -0
- package/dist/src/services/webhook.js +401 -0
- package/dist/src/store/app_db.d.ts +10 -0
- package/dist/src/store/app_db.js +85 -0
- package/dist/src/store/cache_db.d.ts +4 -0
- package/dist/src/store/cache_db.js +63 -0
- package/dist/src/store/deliveries.d.ts +12 -0
- package/dist/src/store/deliveries.js +23 -0
- package/dist/src/store/drift.d.ts +4 -0
- package/dist/src/store/drift.js +22 -0
- package/dist/src/store/findings.d.ts +31 -0
- package/dist/src/store/findings.js +64 -0
- package/dist/src/store/installations.d.ts +9 -0
- package/dist/src/store/installations.js +35 -0
- package/dist/src/store/job_logs.d.ts +5 -0
- package/dist/src/store/job_logs.js +17 -0
- package/dist/src/store/jobs.d.ts +27 -0
- package/dist/src/store/jobs.js +86 -0
- package/dist/src/store/migrations.d.ts +5 -0
- package/dist/src/store/migrations.js +258 -0
- package/dist/src/store/remote_review_inputs.d.ts +11 -0
- package/dist/src/store/remote_review_inputs.js +25 -0
- package/dist/src/store/remote_tokens.d.ts +10 -0
- package/dist/src/store/remote_tokens.js +45 -0
- package/dist/src/store/replies.d.ts +24 -0
- package/dist/src/store/replies.js +79 -0
- package/dist/src/store/repos.d.ts +11 -0
- package/dist/src/store/repos.js +59 -0
- package/dist/src/store/reviews.d.ts +86 -0
- package/dist/src/store/reviews.js +220 -0
- package/dist/src/store/rows.d.ts +179 -0
- package/dist/src/store/rows.js +4 -0
- package/dist/src/store/sessions.d.ts +8 -0
- package/dist/src/store/sessions.js +34 -0
- package/dist/src/store/skill_state.d.ts +3 -0
- package/dist/src/store/skill_state.js +24 -0
- package/dist/src/store/sqlite.d.ts +39 -0
- package/dist/src/store/sqlite.js +77 -0
- package/dist/src/store/subjects.d.ts +15 -0
- package/dist/src/store/subjects.js +78 -0
- package/dist/src/tools/codegraph.d.ts +58 -0
- package/dist/src/tools/codegraph.js +165 -0
- package/dist/src/tools/codegraph_exec.d.ts +13 -0
- package/dist/src/tools/codegraph_exec.js +66 -0
- package/dist/src/types.d.ts +89 -0
- package/dist/src/types.js +1 -0
- package/dist/src/util/atomic.d.ts +4 -0
- package/dist/src/util/atomic.js +78 -0
- package/dist/src/util/keyed_lock.d.ts +3 -0
- package/dist/src/util/keyed_lock.js +33 -0
- package/dist/src/util/log.d.ts +11 -0
- package/dist/src/util/log.js +42 -0
- package/dist/src/util/redact.d.ts +5 -0
- package/dist/src/util/redact.js +30 -0
- package/dist/src/util/runtime.d.ts +90 -0
- package/dist/src/util/runtime.js +206 -0
- package/dist/src/util/time.d.ts +9 -0
- package/dist/src/util/time.js +36 -0
- package/dist/src/version.d.ts +1 -0
- package/dist/src/version.js +5 -0
- package/package.json +54 -0
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
export const MERMAID_TYPES = [
|
|
2
|
+
"flowchart",
|
|
3
|
+
"swimlane-beta",
|
|
4
|
+
"sequenceDiagram",
|
|
5
|
+
"classDiagram",
|
|
6
|
+
"stateDiagram-v2",
|
|
7
|
+
"erDiagram",
|
|
8
|
+
"requirementDiagram",
|
|
9
|
+
"usecase-beta",
|
|
10
|
+
"C4Context",
|
|
11
|
+
"zenuml",
|
|
12
|
+
"packet",
|
|
13
|
+
"architecture-beta",
|
|
14
|
+
"eventmodeling",
|
|
15
|
+
"treeView-beta",
|
|
16
|
+
];
|
|
17
|
+
const DOCS = {
|
|
18
|
+
flowchart: `# flowchart
|
|
19
|
+
Use for decisions, branches, pipelines, and fallback paths.
|
|
20
|
+
Syntax: flowchart LR
|
|
21
|
+
A[Input] --> B{Check}
|
|
22
|
+
B -->|yes| C[Done]
|
|
23
|
+
Use short ids and labels. Directions: TB, TD, BT, LR, RL. Use [] for tasks,
|
|
24
|
+
{} for decisions, and --> for arrows. Optional frontmatter config can set
|
|
25
|
+
flowchart, theme, and themeVariables values documented by Mermaid.`,
|
|
26
|
+
"swimlane-beta": `# swimlane-beta
|
|
27
|
+
Use when work crosses owners, actors, services, teams, or layers.
|
|
28
|
+
Syntax:
|
|
29
|
+
swimlane-beta LR
|
|
30
|
+
subgraph Intake
|
|
31
|
+
request[Request]
|
|
32
|
+
end
|
|
33
|
+
subgraph Worker
|
|
34
|
+
process[Process]
|
|
35
|
+
end
|
|
36
|
+
request --> process
|
|
37
|
+
Top-level subgraph blocks are lanes. Nodes use flowchart shapes. Directions:
|
|
38
|
+
TB, TD, BT, LR, RL. Label cross-lane handoffs. Optional frontmatter config
|
|
39
|
+
may set swimlane and themeVariables values documented by Mermaid.`,
|
|
40
|
+
sequenceDiagram: `# sequenceDiagram
|
|
41
|
+
Use for ordered messages, webhooks, retries, responses, and timing.
|
|
42
|
+
Syntax:
|
|
43
|
+
sequenceDiagram
|
|
44
|
+
participant Client
|
|
45
|
+
participant API
|
|
46
|
+
Client->>API: request
|
|
47
|
+
API-->>Client: response
|
|
48
|
+
Use participant, actor, alt, opt, loop, par, and critical only when supported
|
|
49
|
+
by the evidence. Use ->> for calls and -->> for replies. Optional frontmatter
|
|
50
|
+
config may set sequence and themeVariables values documented by Mermaid.`,
|
|
51
|
+
classDiagram: `# classDiagram
|
|
52
|
+
Use for class, interface, type, inheritance, and composition relationships.
|
|
53
|
+
Syntax:
|
|
54
|
+
classDiagram
|
|
55
|
+
class Review {
|
|
56
|
+
+status: string
|
|
57
|
+
+post()
|
|
58
|
+
}
|
|
59
|
+
Review --> Finding : contains
|
|
60
|
+
Use class blocks for members and -->, <|--, *--, or o-- for relationships.
|
|
61
|
+
Do not invent members. Optional frontmatter config may set class and themeVariables
|
|
62
|
+
values documented by Mermaid.`,
|
|
63
|
+
"stateDiagram-v2": `# stateDiagram-v2
|
|
64
|
+
Use for a lifecycle and its state transitions.
|
|
65
|
+
Syntax:
|
|
66
|
+
stateDiagram-v2
|
|
67
|
+
[*] --> Pending
|
|
68
|
+
Pending --> Running : start
|
|
69
|
+
Running --> Done : finish
|
|
70
|
+
Done --> [*]
|
|
71
|
+
Use [*] for start/end, --> for transitions, and labels after :. Composite
|
|
72
|
+
states use state Name { ... }. Optional frontmatter config may set state and
|
|
73
|
+
themeVariables values documented by Mermaid.`,
|
|
74
|
+
erDiagram: `# erDiagram
|
|
75
|
+
Use for database entities, keys, and cardinality.
|
|
76
|
+
Syntax:
|
|
77
|
+
erDiagram
|
|
78
|
+
REVIEW ||--o{ FINDING : contains
|
|
79
|
+
REVIEW {
|
|
80
|
+
string id PK
|
|
81
|
+
}
|
|
82
|
+
FINDING {
|
|
83
|
+
string review_id FK
|
|
84
|
+
}
|
|
85
|
+
Use ||, o|, ||, }|, and related cardinality markers only when supported.
|
|
86
|
+
Optional frontmatter config may set er and themeVariables values documented
|
|
87
|
+
by Mermaid.`,
|
|
88
|
+
requirementDiagram: `# requirementDiagram
|
|
89
|
+
Use for requirements linked to tests or implementation elements.
|
|
90
|
+
Syntax:
|
|
91
|
+
requirementDiagram
|
|
92
|
+
requirement R {
|
|
93
|
+
id: 1
|
|
94
|
+
text: "Requirement text"
|
|
95
|
+
risk: low
|
|
96
|
+
verifymethod: test
|
|
97
|
+
}
|
|
98
|
+
element E {
|
|
99
|
+
type: test
|
|
100
|
+
}
|
|
101
|
+
E - verifies -> R
|
|
102
|
+
Requirement fields are id, text, risk, and verifymethod. Relationship types
|
|
103
|
+
include contains, derives, satisfies, verifies, refines, and traces. Optional
|
|
104
|
+
frontmatter config may set requirement and themeVariables values documented
|
|
105
|
+
by Mermaid.`,
|
|
106
|
+
"usecase-beta": `# usecase-beta
|
|
107
|
+
Use for actors and system capabilities.
|
|
108
|
+
Syntax:
|
|
109
|
+
usecase-beta
|
|
110
|
+
direction LR
|
|
111
|
+
actor User
|
|
112
|
+
systemBoundary App
|
|
113
|
+
Login("Log in")
|
|
114
|
+
end
|
|
115
|
+
User --> Login
|
|
116
|
+
Use actor declarations, systemBoundary blocks, and --> relationships. Use
|
|
117
|
+
..> for include/extend relationships when the evidence supports them.
|
|
118
|
+
Optional frontmatter config may set usecase and themeVariables values documented
|
|
119
|
+
by Mermaid.`,
|
|
120
|
+
C4Context: `# C4Context
|
|
121
|
+
Use for users, systems, boundaries, and integrations.
|
|
122
|
+
Syntax:
|
|
123
|
+
C4Context
|
|
124
|
+
Person(user, "User")
|
|
125
|
+
System(app, "Application")
|
|
126
|
+
System_Ext(github, "GitHub")
|
|
127
|
+
Rel(user, app, "Uses")
|
|
128
|
+
Rel(app, github, "Calls")
|
|
129
|
+
Use stable aliases and Person, System, System_Ext, SystemDb, Boundary, Rel,
|
|
130
|
+
and BiRel forms. C4 is experimental and compatible with C4-PlantUML style.
|
|
131
|
+
Optional frontmatter config may set c4 and themeVariables values documented
|
|
132
|
+
by Mermaid.`,
|
|
133
|
+
zenuml: `# zenuml
|
|
134
|
+
Use for compact, nested call sequences.
|
|
135
|
+
Syntax:
|
|
136
|
+
zenuml
|
|
137
|
+
Client->API: request
|
|
138
|
+
API->Worker: process
|
|
139
|
+
Worker->API: result
|
|
140
|
+
API->Client: response
|
|
141
|
+
Participants may be implicit. Use nested braces for synchronous calls and
|
|
142
|
+
if/else, loop, opt, par, and try/catch only when useful. Optional frontmatter
|
|
143
|
+
config may set zenuml and themeVariables values documented by Mermaid.`,
|
|
144
|
+
packet: `# packet
|
|
145
|
+
Use for binary packet fields, bit ranges, and protocol layout.
|
|
146
|
+
Syntax:
|
|
147
|
+
packet
|
|
148
|
+
0-7: "Header"
|
|
149
|
+
8-31: "Payload"
|
|
150
|
+
Use explicit bit ranges or +N relative widths. Every field needs a quoted
|
|
151
|
+
label. Do not use this for ordinary JSON or API request flow. Optional
|
|
152
|
+
frontmatter config may set packet and themeVariables values documented by
|
|
153
|
+
Mermaid.`,
|
|
154
|
+
"architecture-beta": `# architecture-beta
|
|
155
|
+
Use for services, containers, storage, deployment, and infrastructure topology.
|
|
156
|
+
Syntax:
|
|
157
|
+
architecture-beta
|
|
158
|
+
group api(cloud)[API]
|
|
159
|
+
service db(database)[Database] in api
|
|
160
|
+
service app(server)[Application] in api
|
|
161
|
+
db:R -- L:app
|
|
162
|
+
Declare groups and services before edges. Built-in icons include cloud,
|
|
163
|
+
database, disk, internet, and server. Edge ports are T, B, L, or R. Optional
|
|
164
|
+
frontmatter config may set architecture, including randomize, seed,
|
|
165
|
+
nodeSeparation, and idealEdgeLengthMultiplier, plus themeVariables.`,
|
|
166
|
+
eventmodeling: `# eventmodeling
|
|
167
|
+
Use for UI/processor actions, commands, read models, and events over time.
|
|
168
|
+
Syntax:
|
|
169
|
+
eventmodeling
|
|
170
|
+
tf 01 ui Screen
|
|
171
|
+
tf 02 cmd Save
|
|
172
|
+
tf 03 evt Saved
|
|
173
|
+
Entity types include ui, pcr, cmd, rmo, and evt. Use unique frame numbers.
|
|
174
|
+
Use rf for a reset frame and ->> for multiple read-model relations. Optional
|
|
175
|
+
frontmatter config may set eventmodeling and themeVariables values documented
|
|
176
|
+
by Mermaid.`,
|
|
177
|
+
"treeView-beta": `# treeView-beta
|
|
178
|
+
Use for directory, file, module, or dependency hierarchies.
|
|
179
|
+
Exact syntax:
|
|
180
|
+
treeView-beta
|
|
181
|
+
project/
|
|
182
|
+
src/
|
|
183
|
+
index.ts
|
|
184
|
+
package.json
|
|
185
|
+
README.md
|
|
186
|
+
Indentation defines parent-child relationships. Directories must end with /.
|
|
187
|
+
Labels may be bare or quoted. Do not use arrows, subgraph, or flowchart node
|
|
188
|
+
syntax. Optional frontmatter config:
|
|
189
|
+
---
|
|
190
|
+
config:
|
|
191
|
+
treeView:
|
|
192
|
+
rowIndent: 80
|
|
193
|
+
lineThickness: 3
|
|
194
|
+
themeVariables:
|
|
195
|
+
treeView:
|
|
196
|
+
labelFontSize: "20px"
|
|
197
|
+
labelColor: "#333333"
|
|
198
|
+
lineColor: "#777777"
|
|
199
|
+
---
|
|
200
|
+
Other documented treeView keys include paddingX, paddingY, showIcons,
|
|
201
|
+
defaultIconPack, filenameIcons, extensionIcons, iconColor, descriptionColor,
|
|
202
|
+
highlightBg, and highlightStroke. Use config only when it improves clarity.`,
|
|
203
|
+
};
|
|
204
|
+
const CONFIG_DOCS = {
|
|
205
|
+
flowchart: `Configuration:
|
|
206
|
+
---
|
|
207
|
+
config:
|
|
208
|
+
flowchart:
|
|
209
|
+
nodeSpacing: 50
|
|
210
|
+
rankSpacing: 50
|
|
211
|
+
padding: 8
|
|
212
|
+
curve: basis
|
|
213
|
+
themeVariables:
|
|
214
|
+
primaryColor: "#e8f0fe"
|
|
215
|
+
lineColor: "#555555"
|
|
216
|
+
---
|
|
217
|
+
Use nodeSpacing/rankSpacing for layout gaps, padding for outer space, and curve
|
|
218
|
+
for edge shape. Add config only when the default layout is hard to read.`,
|
|
219
|
+
"swimlane-beta": `Configuration:
|
|
220
|
+
---
|
|
221
|
+
config:
|
|
222
|
+
swimlane:
|
|
223
|
+
lineHops: arc
|
|
224
|
+
ignoreCrossLaneEdges: true
|
|
225
|
+
optimizeRanksByCrossings: true
|
|
226
|
+
automaticLaneOrdering: false
|
|
227
|
+
themeVariables:
|
|
228
|
+
primaryColor: "#e8f0fe"
|
|
229
|
+
---
|
|
230
|
+
lineHops accepts arc, gap, or false. Keep automaticLaneOrdering false when
|
|
231
|
+
source lane order carries meaning. Swimlane also reuses flowchart spacing.`,
|
|
232
|
+
sequenceDiagram: `Configuration:
|
|
233
|
+
---
|
|
234
|
+
config:
|
|
235
|
+
sequence:
|
|
236
|
+
hideUnusedParticipants: true
|
|
237
|
+
actorMargin: 50
|
|
238
|
+
messageMargin: 35
|
|
239
|
+
mirrorActors: true
|
|
240
|
+
rightAngles: false
|
|
241
|
+
showSequenceNumbers: false
|
|
242
|
+
themeVariables:
|
|
243
|
+
actorBkg: "#e8f0fe"
|
|
244
|
+
signalColor: "#333333"
|
|
245
|
+
---
|
|
246
|
+
Use hideUnusedParticipants to remove unused declarations, actor/message margins
|
|
247
|
+
for spacing, mirrorActors for repeated headers, and showSequenceNumbers only
|
|
248
|
+
when numbered traces are useful.`,
|
|
249
|
+
classDiagram: `Configuration:
|
|
250
|
+
---
|
|
251
|
+
config:
|
|
252
|
+
class:
|
|
253
|
+
nodeSpacing: 50
|
|
254
|
+
rankSpacing: 50
|
|
255
|
+
hideEmptyMembersBox: false
|
|
256
|
+
hierarchicalNamespaces: true
|
|
257
|
+
htmlLabels: false
|
|
258
|
+
themeVariables:
|
|
259
|
+
primaryColor: "#e8f0fe"
|
|
260
|
+
---
|
|
261
|
+
Use spacing for crowded graphs. Set hideEmptyMembersBox when empty compartments
|
|
262
|
+
add noise and hierarchicalNamespaces false for compact dotted namespaces.`,
|
|
263
|
+
"stateDiagram-v2": `Configuration:
|
|
264
|
+
---
|
|
265
|
+
config:
|
|
266
|
+
state:
|
|
267
|
+
padding: 8
|
|
268
|
+
nodeSpacing: 50
|
|
269
|
+
rankSpacing: 50
|
|
270
|
+
dividerMargin: 10
|
|
271
|
+
defaultRenderer: dagre-wrapper
|
|
272
|
+
themeVariables:
|
|
273
|
+
primaryColor: "#e8f0fe"
|
|
274
|
+
lineColor: "#555555"
|
|
275
|
+
---
|
|
276
|
+
Use padding and spacing for readability. Use defaultRenderer only when the
|
|
277
|
+
target renderer supports the chosen renderer.`,
|
|
278
|
+
erDiagram: `Configuration:
|
|
279
|
+
---
|
|
280
|
+
config:
|
|
281
|
+
er:
|
|
282
|
+
layoutDirection: TB
|
|
283
|
+
minEntityWidth: 100
|
|
284
|
+
minEntityHeight: 75
|
|
285
|
+
entityPadding: 15
|
|
286
|
+
nodeSpacing: 140
|
|
287
|
+
rankSpacing: 80
|
|
288
|
+
stroke: "#777777"
|
|
289
|
+
fill: "#f0fff0"
|
|
290
|
+
fontSize: 12
|
|
291
|
+
---
|
|
292
|
+
layoutDirection accepts TB, BT, LR, or RL. Use entity sizes and spacing for
|
|
293
|
+
crowded schemas. Use stroke/fill/fontSize only for readable contrast.`,
|
|
294
|
+
requirementDiagram: `Configuration:
|
|
295
|
+
---
|
|
296
|
+
config:
|
|
297
|
+
requirement:
|
|
298
|
+
rect_fill: "#f9f9f9"
|
|
299
|
+
text_color: "#333333"
|
|
300
|
+
rect_border_size: "0.5px"
|
|
301
|
+
rect_border_color: "#bbbbbb"
|
|
302
|
+
rect_min_width: 200
|
|
303
|
+
rect_min_height: 100
|
|
304
|
+
rect_padding: 10
|
|
305
|
+
line_height: 20
|
|
306
|
+
fontSize: 14
|
|
307
|
+
themeVariables:
|
|
308
|
+
lineColor: "#555555"
|
|
309
|
+
---
|
|
310
|
+
Use rect_* for requirement/element boxes and line_height/fontSize for
|
|
311
|
+
readability. Keep risk and verification semantics in diagram data.`,
|
|
312
|
+
"usecase-beta": `Configuration:
|
|
313
|
+
---
|
|
314
|
+
config:
|
|
315
|
+
usecase:
|
|
316
|
+
actorFontSize: 14
|
|
317
|
+
usecaseFontSize: 12
|
|
318
|
+
actorFontWeight: normal
|
|
319
|
+
usecaseFontWeight: normal
|
|
320
|
+
nodeSpacing: 50
|
|
321
|
+
rankSpacing: 50
|
|
322
|
+
diagramPadding: 20
|
|
323
|
+
themeVariables:
|
|
324
|
+
primaryColor: "#e8f0fe"
|
|
325
|
+
---
|
|
326
|
+
Use font settings for legibility and spacing for crowded actor-capability
|
|
327
|
+
graphs. Font values must not contain ;, <, >, (, ), {, }, or backslash.`,
|
|
328
|
+
C4Context: `Configuration:
|
|
329
|
+
---
|
|
330
|
+
config:
|
|
331
|
+
c4:
|
|
332
|
+
diagramMarginX: 50
|
|
333
|
+
diagramMarginY: 10
|
|
334
|
+
c4ShapeMargin: 50
|
|
335
|
+
c4ShapePadding: 20
|
|
336
|
+
c4ShapeInRow: 4
|
|
337
|
+
c4BoundaryInRow: 2
|
|
338
|
+
width: 216
|
|
339
|
+
height: 60
|
|
340
|
+
useMaxWidth: true
|
|
341
|
+
---
|
|
342
|
+
Use shape margin/padding for spacing, shape/boundary counts for layout density,
|
|
343
|
+
and width/height for box size. C4 is experimental. Do not invent style calls.`,
|
|
344
|
+
zenuml: `Configuration:
|
|
345
|
+
ZenUML is an external Mermaid diagram integration and has no stable dedicated
|
|
346
|
+
zenuml block in Mermaid core config. Do not invent one. Use only frontmatter
|
|
347
|
+
options documented by the target renderer, such as supported title/theme
|
|
348
|
+
settings, and omit config when unsure.`,
|
|
349
|
+
packet: `Configuration:
|
|
350
|
+
---
|
|
351
|
+
config:
|
|
352
|
+
packet:
|
|
353
|
+
rowHeight: 32
|
|
354
|
+
bitWidth: 32
|
|
355
|
+
bitsPerRow: 32
|
|
356
|
+
showBits: true
|
|
357
|
+
paddingX: 5
|
|
358
|
+
paddingY: 5
|
|
359
|
+
themeVariables:
|
|
360
|
+
packetBkg: "#e8f0fe"
|
|
361
|
+
---
|
|
362
|
+
Use bitsPerRow/bitWidth for layout, rowHeight for readability, showBits when
|
|
363
|
+
bit numbering distracts, and paddingX/paddingY for spacing.`,
|
|
364
|
+
"architecture-beta": `Configuration:
|
|
365
|
+
---
|
|
366
|
+
config:
|
|
367
|
+
architecture:
|
|
368
|
+
padding: 40
|
|
369
|
+
iconSize: 80
|
|
370
|
+
fontSize: 16
|
|
371
|
+
randomize: false
|
|
372
|
+
nodeSeparation: 75
|
|
373
|
+
idealEdgeLengthMultiplier: 1.5
|
|
374
|
+
edgeElasticity: 0.45
|
|
375
|
+
numIter: 2500
|
|
376
|
+
seed: 1
|
|
377
|
+
---
|
|
378
|
+
Use padding/iconSize/fontSize for scale. Increase nodeSeparation or
|
|
379
|
+
idealEdgeLengthMultiplier when nodes overlap. Keep randomize false and seed
|
|
380
|
+
stable for reproducible output. Increase numIter only for dense diagrams.`,
|
|
381
|
+
eventmodeling: `Configuration:
|
|
382
|
+
---
|
|
383
|
+
config:
|
|
384
|
+
eventmodeling:
|
|
385
|
+
padding: 30
|
|
386
|
+
rowHeight: 32
|
|
387
|
+
themeVariables:
|
|
388
|
+
primaryColor: "#e8f0fe"
|
|
389
|
+
---
|
|
390
|
+
Use padding for outer space and rowHeight for timeline readability. Do not use
|
|
391
|
+
config to hide incorrect frame numbers or inferred relations.`,
|
|
392
|
+
"treeView-beta": `Configuration:
|
|
393
|
+
---
|
|
394
|
+
config:
|
|
395
|
+
treeView:
|
|
396
|
+
rowIndent: 80
|
|
397
|
+
paddingX: 5
|
|
398
|
+
paddingY: 5
|
|
399
|
+
lineThickness: 3
|
|
400
|
+
showIcons: true
|
|
401
|
+
defaultIconPack: material-icon-theme
|
|
402
|
+
filenameIcons:
|
|
403
|
+
Dockerfile: docker
|
|
404
|
+
extensionIcons:
|
|
405
|
+
.ts: typescript
|
|
406
|
+
themeVariables:
|
|
407
|
+
treeView:
|
|
408
|
+
labelFontSize: "20px"
|
|
409
|
+
labelColor: "#333333"
|
|
410
|
+
lineColor: "#777777"
|
|
411
|
+
iconColor: "#546e7a"
|
|
412
|
+
descriptionColor: "#6a9955"
|
|
413
|
+
highlightBg: "rgba(255,193,7,0.15)"
|
|
414
|
+
highlightStroke: "#ffc107"
|
|
415
|
+
---
|
|
416
|
+
rowIndent controls nesting distance, paddingX/Y label spacing, lineThickness
|
|
417
|
+
connector weight, and showIcons file/folder icons. Icon packs must be
|
|
418
|
+
registered by the renderer. Directories still require / and indentation.`,
|
|
419
|
+
};
|
|
420
|
+
export const MERMAID_TOOL = {
|
|
421
|
+
type: "function",
|
|
422
|
+
function: {
|
|
423
|
+
name: "read-mermaid-syntaxes",
|
|
424
|
+
description: "Read the LLM-friendly syntax, configuration, and examples for selected Mermaid diagram types.",
|
|
425
|
+
parameters: {
|
|
426
|
+
type: "object",
|
|
427
|
+
properties: {
|
|
428
|
+
tools: {
|
|
429
|
+
type: "array",
|
|
430
|
+
items: { type: "string", enum: [...MERMAID_TYPES] },
|
|
431
|
+
uniqueItems: true,
|
|
432
|
+
maxItems: 5,
|
|
433
|
+
},
|
|
434
|
+
},
|
|
435
|
+
required: ["tools"],
|
|
436
|
+
additionalProperties: false,
|
|
437
|
+
},
|
|
438
|
+
},
|
|
439
|
+
};
|
|
440
|
+
export function readMermaidSyntaxes(args, maxTools) {
|
|
441
|
+
const raw = args.tools;
|
|
442
|
+
if (!Array.isArray(raw)) {
|
|
443
|
+
throw new Error("read-mermaid-syntaxes requires a tools array");
|
|
444
|
+
}
|
|
445
|
+
const names = [...new Set(raw.map(String))];
|
|
446
|
+
if (names.length === 0 || names.length > maxTools) {
|
|
447
|
+
throw new Error(`read-mermaid-syntaxes accepts 1-${maxTools} tools`);
|
|
448
|
+
}
|
|
449
|
+
for (const name of names) {
|
|
450
|
+
if (!MERMAID_TYPES.includes(name)) {
|
|
451
|
+
throw new Error(`unsupported Mermaid syntax: ${name}`);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return names
|
|
455
|
+
.map((name) => `${DOCS[name]}\n\n${CONFIG_DOCS[name]}`)
|
|
456
|
+
.join("\n\n");
|
|
457
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AiProvider, AiRequest, AiResponse, Json } from "../types.ts";
|
|
2
|
+
/** Async because a review's tools shell out or hit disk, unlike the built-in
|
|
3
|
+
* Mermaid doc lookup. */
|
|
4
|
+
export type ToolHandler = {
|
|
5
|
+
tool: Json;
|
|
6
|
+
name: string;
|
|
7
|
+
run: (args: unknown) => Promise<string> | string;
|
|
8
|
+
};
|
|
9
|
+
export declare function completeWithMermaidTools(provider: AiProvider, request: AiRequest, maxTools: number, extraTools?: ToolHandler[], maxToolRounds?: number, options?: {
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
onResponse?: (response: AiResponse) => void | Promise<void>;
|
|
12
|
+
}): Promise<AiResponse>;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { MERMAID_TOOL, readMermaidSyntaxes } from "./mermaid.js";
|
|
2
|
+
import { log } from "../util/log.js";
|
|
3
|
+
const DEFAULT_MAX_TOOL_ROUNDS = 3;
|
|
4
|
+
const TOOL_NAME = "read-mermaid-syntaxes";
|
|
5
|
+
async function runTool(call, maxTools, extraTools) {
|
|
6
|
+
try {
|
|
7
|
+
if (call.function.name === TOOL_NAME) {
|
|
8
|
+
return readMermaidSyntaxes(JSON.parse(call.function.arguments), maxTools);
|
|
9
|
+
}
|
|
10
|
+
const extra = extraTools.find((item) => item.name === call.function.name);
|
|
11
|
+
if (extra)
|
|
12
|
+
return await extra.run(JSON.parse(call.function.arguments));
|
|
13
|
+
throw new Error(`unsupported tool: ${call.function.name}`);
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
return `Tool error: ${error instanceof Error ? error.message : String(error)}`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export async function completeWithMermaidTools(provider, request, maxTools, extraTools = [], maxToolRounds = DEFAULT_MAX_TOOL_ROUNDS, options = {}) {
|
|
20
|
+
if (provider.supportsTools === false) {
|
|
21
|
+
const response = await provider.complete(request);
|
|
22
|
+
if (options.onResponse)
|
|
23
|
+
await options.onResponse(response);
|
|
24
|
+
return response;
|
|
25
|
+
}
|
|
26
|
+
const messages = [
|
|
27
|
+
...(request.messages ?? [
|
|
28
|
+
...(request.system
|
|
29
|
+
? [{ role: "system", content: request.system }]
|
|
30
|
+
: []),
|
|
31
|
+
{ role: "user", content: request.prompt },
|
|
32
|
+
]),
|
|
33
|
+
];
|
|
34
|
+
const tools = [
|
|
35
|
+
MERMAID_TOOL,
|
|
36
|
+
...extraTools.map((item) => item.tool),
|
|
37
|
+
];
|
|
38
|
+
const totals = {
|
|
39
|
+
tokensIn: 0,
|
|
40
|
+
tokensOut: 0,
|
|
41
|
+
cost: undefined,
|
|
42
|
+
};
|
|
43
|
+
let costKnown = true;
|
|
44
|
+
const merge = (response) => {
|
|
45
|
+
totals.tokensIn += response.tokensIn;
|
|
46
|
+
totals.tokensOut += response.tokensOut;
|
|
47
|
+
if (response.cost === undefined)
|
|
48
|
+
costKnown = false;
|
|
49
|
+
else if (costKnown)
|
|
50
|
+
totals.cost = (totals.cost ?? 0) + response.cost;
|
|
51
|
+
return {
|
|
52
|
+
...response,
|
|
53
|
+
...totals,
|
|
54
|
+
cost: costKnown ? totals.cost : undefined,
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
for (let round = 0; round < maxToolRounds; round++) {
|
|
58
|
+
if (options.signal?.aborted) {
|
|
59
|
+
throw new DOMException("Aborted", "AbortError");
|
|
60
|
+
}
|
|
61
|
+
const response = await provider.complete({ ...request, messages, tools });
|
|
62
|
+
if (options.onResponse)
|
|
63
|
+
await options.onResponse(response);
|
|
64
|
+
if (!response.toolCalls?.length)
|
|
65
|
+
return merge(response);
|
|
66
|
+
merge(response);
|
|
67
|
+
log("review-tools", `round ${round + 1}/${maxToolRounds} · ${response.toolCalls.length} call(s): ${response.toolCalls
|
|
68
|
+
.map((call) => call.function.name)
|
|
69
|
+
.join(", ")}`);
|
|
70
|
+
messages.push({
|
|
71
|
+
role: "assistant",
|
|
72
|
+
content: response.text || null,
|
|
73
|
+
tool_calls: response.toolCalls,
|
|
74
|
+
});
|
|
75
|
+
const results = await Promise.all(response.toolCalls.map(async (call) => {
|
|
76
|
+
const result = await runTool(call, maxTools, extraTools);
|
|
77
|
+
log("review-tools", `${call.function.name}(${call.function.arguments}) → ${result.length} chars${result.startsWith("Tool error") || result.startsWith("codegraph ")
|
|
78
|
+
? `: ${result.slice(0, 200)}`
|
|
79
|
+
: ""}`);
|
|
80
|
+
return { call, result };
|
|
81
|
+
}));
|
|
82
|
+
for (const { call, result } of results) {
|
|
83
|
+
messages.push({
|
|
84
|
+
role: "tool",
|
|
85
|
+
tool_call_id: call.id,
|
|
86
|
+
name: call.function.name,
|
|
87
|
+
content: result,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
log("review-tools", `round budget (${maxToolRounds}) exhausted with the model still requesting tools`);
|
|
92
|
+
messages.push({
|
|
93
|
+
role: "user",
|
|
94
|
+
content: "No more tool calls are available. Answer now using only what you already found.",
|
|
95
|
+
});
|
|
96
|
+
const final = await provider.complete({ ...request, messages });
|
|
97
|
+
if (options.onResponse)
|
|
98
|
+
await options.onResponse(final);
|
|
99
|
+
return merge(final);
|
|
100
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AiProvider, AiRequest, AiResponse } from "../types.ts";
|
|
2
|
+
export declare class OpenRouterProvider implements AiProvider {
|
|
3
|
+
readonly supportsTools = true;
|
|
4
|
+
private readonly endpoint;
|
|
5
|
+
private readonly apiKey;
|
|
6
|
+
private readonly model;
|
|
7
|
+
constructor(apiKey: string, model: string);
|
|
8
|
+
complete(request: AiRequest): Promise<AiResponse>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { chatBody, parseChatResponse } from "./provider.js";
|
|
2
|
+
export class OpenRouterProvider {
|
|
3
|
+
supportsTools = true;
|
|
4
|
+
endpoint = "https://openrouter.ai/api/v1/chat/completions";
|
|
5
|
+
apiKey;
|
|
6
|
+
model;
|
|
7
|
+
constructor(apiKey, model) {
|
|
8
|
+
if (!apiKey)
|
|
9
|
+
throw new Error("OpenRouter requires OPENROUTER_API_KEY");
|
|
10
|
+
this.apiKey = apiKey;
|
|
11
|
+
this.model = model;
|
|
12
|
+
}
|
|
13
|
+
async complete(request) {
|
|
14
|
+
const response = await fetch(this.endpoint, {
|
|
15
|
+
method: "POST",
|
|
16
|
+
headers: {
|
|
17
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
18
|
+
"Content-Type": "application/json",
|
|
19
|
+
"HTTP-Referer": "https://github.com/GroophyLifefor/co-maintainer",
|
|
20
|
+
"X-Title": "co-maintainer",
|
|
21
|
+
},
|
|
22
|
+
body: JSON.stringify(chatBody(this.model, request)),
|
|
23
|
+
});
|
|
24
|
+
if (!response.ok) {
|
|
25
|
+
throw new Error(`OpenRouter ${response.status}: ${await response.text()}`);
|
|
26
|
+
}
|
|
27
|
+
return parseChatResponse((await response.json()), "openrouter", this.model);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AiProvider, AiRequest, AiResponse, Json, Options } from "../types.ts";
|
|
2
|
+
export declare function createAiProvider(options: Options, model: string): AiProvider | undefined;
|
|
3
|
+
export declare function parseChatResponse(json: Json, provider: AiResponse["provider"], model: string): AiResponse;
|
|
4
|
+
export declare function chatBody(model: string, request: AiRequest): Json;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { HetznerProvider } from "./hetzner.js";
|
|
2
|
+
import { OpenRouterProvider } from "./openrouter.js";
|
|
3
|
+
export function createAiProvider(options, model) {
|
|
4
|
+
if (options.ai === "none")
|
|
5
|
+
return undefined;
|
|
6
|
+
if (options.ai === "openrouter") {
|
|
7
|
+
return new OpenRouterProvider(options.aiToken ?? "", model);
|
|
8
|
+
}
|
|
9
|
+
return new HetznerProvider(options.aiToken ?? "", model);
|
|
10
|
+
}
|
|
11
|
+
export function parseChatResponse(json, provider, model) {
|
|
12
|
+
const choice = Array.isArray(json.choices)
|
|
13
|
+
? json.choices[0]
|
|
14
|
+
: undefined;
|
|
15
|
+
const message = choice?.message;
|
|
16
|
+
const usage = json.usage;
|
|
17
|
+
const cost = Number(usage?.cost ?? usage?.cost_details?.total_cost);
|
|
18
|
+
const toolCalls = Array.isArray(message?.tool_calls)
|
|
19
|
+
? message.tool_calls
|
|
20
|
+
.map((call) => {
|
|
21
|
+
const value = call;
|
|
22
|
+
const fn = value.function;
|
|
23
|
+
return {
|
|
24
|
+
id: String(value.id ?? ""),
|
|
25
|
+
type: "function",
|
|
26
|
+
function: {
|
|
27
|
+
name: String(fn?.name ?? ""),
|
|
28
|
+
arguments: String(fn?.arguments ?? "{}"),
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
})
|
|
32
|
+
.filter((call) => call.id && call.function.name)
|
|
33
|
+
: undefined;
|
|
34
|
+
return {
|
|
35
|
+
text: String(message?.content ?? ""),
|
|
36
|
+
...(toolCalls?.length ? { toolCalls } : {}),
|
|
37
|
+
tokensIn: Number(usage?.prompt_tokens ?? 0),
|
|
38
|
+
tokensOut: Number(usage?.completion_tokens ?? 0),
|
|
39
|
+
cost: Number.isFinite(cost) ? cost : undefined,
|
|
40
|
+
model,
|
|
41
|
+
provider,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export function chatBody(model, request) {
|
|
45
|
+
const messages = request.messages ?? [
|
|
46
|
+
...(request.system
|
|
47
|
+
? [{ role: "system", content: request.system }]
|
|
48
|
+
: []),
|
|
49
|
+
{ role: "user", content: request.prompt },
|
|
50
|
+
];
|
|
51
|
+
return {
|
|
52
|
+
model,
|
|
53
|
+
temperature: 0,
|
|
54
|
+
max_tokens: request.maxTokens,
|
|
55
|
+
...(request.reasoningEffort
|
|
56
|
+
? { reasoning: { effort: request.reasoningEffort } }
|
|
57
|
+
: {}),
|
|
58
|
+
messages,
|
|
59
|
+
...(request.tools?.length
|
|
60
|
+
? { tools: request.tools, tool_choice: "auto" }
|
|
61
|
+
: {}),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Options } from "../types.ts";
|
|
2
|
+
export declare const defaultLowModel = "openai/gpt-oss-120b";
|
|
3
|
+
/** Plan §8.7 — `--json` must not prompt. */
|
|
4
|
+
export declare function setCliInteractive(value: boolean): void;
|
|
5
|
+
export declare function parseArgs(args: string[]): Promise<Options>;
|