@fa-software/semi2-dsh 0.0.18 → 0.0.19-preview.20261001161030

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.
Files changed (67) hide show
  1. package/lib/api/bootstrap.js +45 -0
  2. package/lib/api/generated/http.js +1 -0
  3. package/lib/api/http-assets.js +89 -0
  4. package/lib/api/http-models.js +101 -0
  5. package/lib/api/http.js +99 -0
  6. package/lib/api/index.js +1 -72
  7. package/lib/api/login.js +3 -10
  8. package/lib/api/operations.js +9 -0
  9. package/lib/api/rest.js +57 -0
  10. package/lib/client.js.map +1 -1
  11. package/lib/cnb-token.js +37 -0
  12. package/lib/domains/default-model/domain.js +1 -3
  13. package/lib/domains/models/domain.js +3 -5
  14. package/lib/domains/models/web-search.js +2 -4
  15. package/lib/domains/project-profile/domain.js +1 -3
  16. package/lib/domains/project-profile/index.js +2 -2
  17. package/lib/domains/redmine/domain.js +1 -4
  18. package/lib/domains/redmine/index.js +2 -2
  19. package/lib/domains/secrets/domain.js +2 -6
  20. package/lib/domains/self-portrait/domain.js +1 -3
  21. package/lib/domains/self-portrait/index.js +1 -1
  22. package/lib/domains/skills/index.js +1 -1
  23. package/lib/domains/skills/mcp-resources.js +8 -10
  24. package/lib/domains/skills/provider.js +4 -4
  25. package/lib/domains/workspace/domain.js +3 -3
  26. package/lib/domains/workspace/feed.js +1 -1
  27. package/lib/domains/workspace/index.js +1 -1
  28. package/lib/domains/workspace/resolve.js +2 -4
  29. package/lib/hub/compile.js +5 -17
  30. package/lib/hub/credentials.js +3 -8
  31. package/lib/hub/errors.js +1 -3
  32. package/lib/hub/status.js +1 -1
  33. package/lib/hub/workspace-book.js +2 -6
  34. package/lib/index.js +3 -2
  35. package/lib/service/config-service.js +3 -4
  36. package/lib/service/connection.js +1 -1
  37. package/lib/service/lifecycle.js +3 -3
  38. package/lib/service/orchestrator.js +2 -4
  39. package/lib/service/ports.js +4 -4
  40. package/lib/service/registry.js +2 -8
  41. package/lib/service/sessions.js +5 -10
  42. package/lib/service/settings-tx.js +3 -6
  43. package/lib/service/status.js +4 -8
  44. package/lib/types/api/bootstrap.d.ts +23 -0
  45. package/lib/types/api/facts.d.ts +41 -0
  46. package/lib/types/api/generated/http.d.ts +3924 -0
  47. package/lib/types/api/http-assets.d.ts +65 -0
  48. package/lib/types/api/http-models.d.ts +68 -0
  49. package/lib/types/api/http.d.ts +16 -0
  50. package/lib/types/api/index.d.ts +10 -31
  51. package/lib/types/api/operations.d.ts +27 -0
  52. package/lib/types/api/rest.d.ts +3 -0
  53. package/lib/types/cnb-token.d.ts +24 -0
  54. package/lib/types/domains/project-profile/domain.d.ts +1 -1
  55. package/lib/types/hub/compile.d.ts +5 -5
  56. package/lib/types/index.d.ts +7 -5
  57. package/lib/types/service/config-service.d.ts +1 -1
  58. package/lib/web/action-routes.js +1 -3
  59. package/lib/web/index.js +2 -2
  60. package/lib/web/welcome-ack.js +6 -5
  61. package/package.json +3 -5
  62. package/lib/api/client.js +0 -119
  63. package/lib/api/generated/documents.js +0 -125
  64. package/lib/types/api/client.d.ts +0 -29
  65. package/lib/types/api/generated/documents.d.ts +0 -15
  66. package/lib/types/api/generated/graphql.d.ts +0 -184
  67. /package/lib/api/{generated/graphql.js → facts.js} +0 -0
@@ -0,0 +1,65 @@
1
+ import type { operations } from './generated/http.ts';
2
+ export declare function decodeFile(value: unknown): {
3
+ path: string;
4
+ sizeBytes: number;
5
+ mimeType: string;
6
+ isExecutable: boolean;
7
+ };
8
+ export declare function decodeFileContent(value: unknown): operations['runtimeSkillFiles']['responses'][200]['content']['application/json'][number];
9
+ export declare function decodeSkill(value: unknown): {
10
+ id: string;
11
+ projectId: string | null;
12
+ name: string;
13
+ description: string;
14
+ whenToUse: string | null;
15
+ invocation: {
16
+ modelInvocable: boolean;
17
+ userInvocable: boolean;
18
+ };
19
+ metadata: Record<string, unknown> | null;
20
+ content: string;
21
+ version: number;
22
+ files: {
23
+ path: string;
24
+ sizeBytes: number;
25
+ mimeType: string;
26
+ isExecutable: boolean;
27
+ }[];
28
+ fileCount: number;
29
+ filesBytes: number;
30
+ };
31
+ export declare function decodeProject(value: unknown): {
32
+ id: string;
33
+ slug: string;
34
+ name: string;
35
+ enabled: boolean;
36
+ planModelId: string | null;
37
+ executeModelId: string | null;
38
+ planReasoningLevel: "OFF" | "MINIMAL" | "LOW" | "MEDIUM" | "HIGH" | "XHIGH" | "MAX" | null;
39
+ executeReasoningLevel: "OFF" | "MINIMAL" | "LOW" | "MEDIUM" | "HIGH" | "XHIGH" | "MAX" | null;
40
+ };
41
+ export declare function decodeProfile(value: unknown): {
42
+ projectName: string;
43
+ projectSlug: string;
44
+ redmineProjectId: number | null;
45
+ redmine: {
46
+ id: number;
47
+ identifier: string;
48
+ name: string;
49
+ status: number;
50
+ homepage: string | null;
51
+ description: string | null;
52
+ truncated: boolean;
53
+ customFields: {
54
+ name: string;
55
+ value: string;
56
+ }[];
57
+ } | null;
58
+ };
59
+ export declare function decodeEvent(value: unknown): {
60
+ id: string;
61
+ action: string;
62
+ outcome: 'SUCCESS' | 'DENIED' | 'ERROR';
63
+ code: string | null;
64
+ occurredAt: string;
65
+ };
@@ -0,0 +1,68 @@
1
+ export declare function record(value: unknown): Record<string, unknown>;
2
+ export declare function string(value: unknown): string;
3
+ export declare function nullableString(value: unknown): string | null;
4
+ export declare function array<T>(value: unknown, decode: (entry: unknown) => T): T[];
5
+ export declare function boolean(value: unknown): boolean;
6
+ export declare function integer(value: unknown): number;
7
+ export declare function protocol(value: unknown): 'DEEPSEEK' | 'OPENAI_CHAT' | 'OPENAI_RESPONSES' | 'ANTHROPIC';
8
+ export declare function reasoning(value: unknown): 'OFF' | 'MINIMAL' | 'LOW' | 'MEDIUM' | 'HIGH' | 'XHIGH' | 'MAX' | null;
9
+ export declare function decodeModel(value: unknown): {
10
+ id: string;
11
+ upstreamId: string;
12
+ displayName: string | null;
13
+ defaultReasoningLevel: "OFF" | "MINIMAL" | "LOW" | "MEDIUM" | "HIGH" | "XHIGH" | "MAX" | null;
14
+ connection: {
15
+ id: string;
16
+ provider: string | null;
17
+ protocol: "DEEPSEEK" | "OPENAI_CHAT" | "OPENAI_RESPONSES" | "ANTHROPIC";
18
+ baseUrl: string;
19
+ };
20
+ metadata: {
21
+ contextWindow: number | null;
22
+ maxTokens: number | null;
23
+ input: ("TEXT" | "IMAGE")[] | null;
24
+ reasoningLevels: ("OFF" | "MINIMAL" | "LOW" | "MEDIUM" | "HIGH" | "XHIGH" | "MAX")[] | null;
25
+ };
26
+ };
27
+ export declare function decodeCredential(value: unknown): {
28
+ connectionId: string;
29
+ value: string;
30
+ };
31
+ export declare function decodeModelConfiguration(value: unknown): {
32
+ models: {
33
+ id: string;
34
+ upstreamId: string;
35
+ displayName: string | null;
36
+ defaultReasoningLevel: "OFF" | "MINIMAL" | "LOW" | "MEDIUM" | "HIGH" | "XHIGH" | "MAX" | null;
37
+ connection: {
38
+ id: string;
39
+ provider: string | null;
40
+ protocol: "DEEPSEEK" | "OPENAI_CHAT" | "OPENAI_RESPONSES" | "ANTHROPIC";
41
+ baseUrl: string;
42
+ };
43
+ metadata: {
44
+ contextWindow: number | null;
45
+ maxTokens: number | null;
46
+ input: ("TEXT" | "IMAGE")[] | null;
47
+ reasoningLevels: ("OFF" | "MINIMAL" | "LOW" | "MEDIUM" | "HIGH" | "XHIGH" | "MAX")[] | null;
48
+ };
49
+ }[];
50
+ credentials: {
51
+ connectionId: string;
52
+ value: string;
53
+ }[];
54
+ defaults: {
55
+ web: {
56
+ modelId: string | null;
57
+ reasoningLevel: "OFF" | "MINIMAL" | "LOW" | "MEDIUM" | "HIGH" | "XHIGH" | "MAX" | null;
58
+ };
59
+ plan: {
60
+ modelId: string | null;
61
+ reasoningLevel: "OFF" | "MINIMAL" | "LOW" | "MEDIUM" | "HIGH" | "XHIGH" | "MAX" | null;
62
+ };
63
+ execute: {
64
+ modelId: string | null;
65
+ reasoningLevel: "OFF" | "MINIMAL" | "LOW" | "MEDIUM" | "HIGH" | "XHIGH" | "MAX" | null;
66
+ };
67
+ };
68
+ };
@@ -0,0 +1,16 @@
1
+ export interface HttpClientOptions {
2
+ baseUrl: string;
3
+ token: string;
4
+ nodeEnv?: string;
5
+ creator?: string;
6
+ channel?: string;
7
+ fetchImpl?: typeof fetch;
8
+ }
9
+ export interface HttpOutcome {
10
+ data: unknown;
11
+ errorCode: string | null;
12
+ }
13
+ /** 保留部署路径前缀;操作路径只能由代码提供,不能跨 origin 或向上跳转。 */
14
+ export declare function runtimeEndpoint(baseUrl: string, path: string, nodeEnv?: string): URL;
15
+ /** 不信任远端 DTO:返回 unknown,由每个业务入口完成结构校验。 */
16
+ export declare function requestRuntime(options: HttpClientOptions, path: string, body?: unknown): Promise<HttpOutcome>;
@@ -1,27 +1,20 @@
1
- import type { RuntimeBootQuery, RuntimeModelCredentialsQuery, RuntimeProjectProfileQuery, RuntimeSkillFilesQuery, RuntimeWorkspaceProjectsQuery } from './generated/graphql.ts';
2
- import type { RuntimeReportEventMutation } from './generated/graphql.ts';
1
+ import type { BootFacts, CredentialFacts, ProjectProfileFacts, SkillFileFacts, WorkspaceFacts, ReportedEventFacts } from './facts.ts';
3
2
  import type { ConnectionCredentials } from '../hub/credentials.ts';
4
3
  import type { ConsoleLoginInput, ConsoleLoginOutcome } from './login.ts';
4
+ export { createRestApi as createSemi2Api } from './rest.ts';
5
5
  export type RuntimeBootFacts = {
6
- [K in keyof RuntimeBootQuery]?: RuntimeBootQuery[K] | null;
6
+ [K in keyof BootFacts]?: BootFacts[K] | null;
7
7
  };
8
- /** 一次运行端读取的结果:`data` 为信封 data(可空),`errorCode` 为领域失败码。 */
9
8
  export interface DomainOutcome<TData> {
10
9
  data: TData | null;
11
10
  errorCode: string | null;
12
11
  }
13
12
  export interface Semi2Api {
14
- /** 五个用户级领域一个文档(模型 / 密钥 / 技能 / 身份 / 默认模型);项目绑定另按工作区取。 */
15
13
  boot(): Promise<DomainOutcome<RuntimeBootFacts>>;
16
- /** 已登记工作区命中的项目绑定(按 slug 点名取,不拉全量表)。 */
17
- workspaceProjects(slugs: readonly string[]): Promise<DomainOutcome<RuntimeWorkspaceProjectsQuery>>;
18
- /** 某 semi2 项目的 Redmine 画像(hub 用读取者本人密钥读取;未关联为空画像)。 */
19
- projectProfile(projectId: string): Promise<DomainOutcome<RuntimeProjectProfileQuery>>;
20
- /** 某技能 head 版本的附件字节(加载该技能时按需取)。 */
21
- skillFiles(skillId: string): Promise<DomainOutcome<RuntimeSkillFilesQuery>>;
22
- /** 连接级模型密钥重取(「重新加载」时只刷新密钥)。 */
23
- modelCredentials(connectionIds?: readonly string[]): Promise<DomainOutcome<RuntimeModelCredentialsQuery>>;
24
- /** CNB 运行端:平台短期 CNB_TOKEN 换 hub 用户密钥。 */
14
+ workspaceProjects(slugs: readonly string[]): Promise<DomainOutcome<WorkspaceFacts>>;
15
+ projectProfile(projectId: string): Promise<DomainOutcome<ProjectProfileFacts>>;
16
+ skillFiles(skillId: string): Promise<DomainOutcome<SkillFileFacts>>;
17
+ modelCredentials(connectionIds?: readonly string[]): Promise<DomainOutcome<CredentialFacts>>;
25
18
  exchangeCnbToken(input: {
26
19
  url: string;
27
20
  token: string;
@@ -29,15 +22,10 @@ export interface Semi2Api {
29
22
  userName: string;
30
23
  token: string;
31
24
  }>;
32
- /** 密码登录换无会话用户密钥(密码只在本次请求内存里)。 */
33
25
  loginToConsole(input: ConsoleLoginInput): Promise<ConsoleLoginOutcome>;
34
- /** 运行端生命周期上报(会话起手 / 创建 / 销毁 / 拒绝 / 交付);失败不改变运行端行为。 */
35
- reportEvent(event: RuntimeEventReport): Promise<DomainOutcome<RuntimeReportEventMutation>>;
26
+ reportEvent(event: RuntimeEventReport): Promise<DomainOutcome<ReportedEventFacts>>;
36
27
  }
37
- /**
38
- * 上报载荷:action / outcome 用 SDL 的枚举名(`SESSION_REFUSED` / `SUCCESS`),
39
- * 与 hub 契约同名同义,两侧不各维护一张映射表。
40
- */
28
+ /** 上报只包含事实;用户身份由服务器根据认证凭据确定。 */
41
29
  export interface RuntimeEventReport {
42
30
  action: string;
43
31
  outcome: 'SUCCESS' | 'DENIED' | 'ERROR';
@@ -45,27 +33,18 @@ export interface RuntimeEventReport {
45
33
  projectSlug?: string;
46
34
  targetLabel?: string;
47
35
  detail?: Record<string, unknown>;
48
- /** dsh 会话 id:会话创建 / 销毁事件给出,hub 按它折叠会话行。 */
49
36
  sessionId?: string;
50
- /** 运行端实例标识:同名 dsh 会话在不同容器里靠它分开。 */
51
37
  clientId?: string;
52
- /** 任务引用:NPC 一次任务的稳定身份(会话尚未创建的事件也带)。 */
53
38
  runRef?: string;
54
- /** 本端工作区:会话 cwd 与命中的已登记工作区 slug。 */
55
39
  workspacePath?: string;
56
40
  workspaceSlug?: string;
57
- /** 会话使用的模型与档位。 */
58
41
  modelId?: string;
59
42
  reasoningLevel?: string;
60
43
  }
61
- /** 上报结果的信封根字段值(即 `data.runtimeReportEvent`)。 */
62
- export type RuntimeReportedEvent = RuntimeReportEventMutation['runtimeReportEvent'];
44
+ export type RuntimeReportedEvent = ReportedEventFacts['runtimeReportEvent'];
63
45
  export interface Semi2ApiOptions {
64
- /** 当前连接凭据(编排层持有权威副本);null = 未配置,调用会抛 MISSING_ACCESS_TOKEN。 */
65
46
  readConnection(): ConnectionCredentials | null;
66
47
  environment: NodeJS.ProcessEnv;
67
- /** 本端标识(运行端契约的 channel);未解析到契约时缺省,hub 记 unknown。 */
68
48
  readChannel?: () => string | undefined;
69
49
  fetchImpl?: typeof fetch;
70
50
  }
71
- export declare function createSemi2Api(options: Semi2ApiOptions): Semi2Api;
@@ -0,0 +1,27 @@
1
+ /** 领域操作名与 HTTP 契约 operationId 对应;路径由实际请求适配器使用。 */
2
+ export declare const RUNTIME_OPERATIONS: {
3
+ RuntimeBoot: {
4
+ operationId: "runtimeBootstrap";
5
+ path: string;
6
+ };
7
+ RuntimeWorkspaceProjects: {
8
+ operationId: "runtimeProjects";
9
+ path: string;
10
+ };
11
+ RuntimeModelCredentials: {
12
+ operationId: "runtimeCredentials";
13
+ path: string;
14
+ };
15
+ RuntimeSkillFiles: {
16
+ operationId: "runtimeSkillFiles";
17
+ path: string;
18
+ };
19
+ RuntimeProjectProfile: {
20
+ operationId: "runtimeProjectProfile";
21
+ path: string;
22
+ };
23
+ RuntimeReportEvent: {
24
+ operationId: "runtimeReportEvent";
25
+ path: string;
26
+ };
27
+ };
@@ -0,0 +1,3 @@
1
+ import type { Semi2Api, Semi2ApiOptions } from './index.ts';
2
+ /** 六个业务读取入口,不把服务端资源路径泄漏进领域编排。 */
3
+ export declare function createRestApi(options: Semi2ApiOptions): Semi2Api;
@@ -0,0 +1,24 @@
1
+ /** 落盘结果:written = 就位;skipped = 不是 CNB 作业;failed = 只降级,绝不抛。 */
2
+ export type CnbTokenOutcome = {
3
+ kind: 'written';
4
+ path: string;
5
+ } | {
6
+ kind: 'skipped';
7
+ path: string;
8
+ reason: string;
9
+ } | {
10
+ kind: 'failed';
11
+ path: string;
12
+ reason: string;
13
+ };
14
+ export interface CnbTokenOptions {
15
+ env?: NodeJS.ProcessEnv;
16
+ home?: string;
17
+ }
18
+ /** 与 cnb CLI 的 getTokenPath 一致:`<home>/.cnb/token`。 */
19
+ export declare function cnbTokenPath(home: string): string;
20
+ /**
21
+ * 把作业的 CNB_TOKEN 落成 cnb CLI 的令牌文件(CLI 只强依赖这两个字段,其余走默认值)。
22
+ * 只在 CNB 作业里动手(`CNB_TOKEN` + `CNB_REPO_SLUG` 齐备),免得开发机上导出的 `CNB_TOKEN` 覆盖个人登录。
23
+ */
24
+ export declare function writeCnbSessionToken(options?: CnbTokenOptions): CnbTokenOutcome;
@@ -1,6 +1,6 @@
1
1
  import type { Semi2ConfigState } from '../../hub/facts.ts';
2
2
  import type { DomainHost, DomainService, RevertRun } from '../types.ts';
3
- /** 一次装配拿到的 Redmine 画像(结构类型,领域不依赖 GraphQL 生成物)。 */
3
+ /** 一次装配拿到的 Redmine 画像(结构类型,领域不依赖 HTTP 传输生成物)。 */
4
4
  export interface ProjectProfile {
5
5
  projectName: string;
6
6
  projectSlug: string;
@@ -1,13 +1,13 @@
1
- import type { InputModality, ModelProtocol, ReasoningLevel, RuntimeBootQuery, RuntimeWorkspaceProjectsQuery } from '../api/generated/graphql.ts';
1
+ import type { InputModality, ModelProtocol, ReasoningLevel, BootFacts, WorkspaceFacts } from '../api/facts.ts';
2
2
  /**
3
3
  * 生效可用目录的一条(连接启用 ∧ 模型启用 ∧ 存在性 ∧ 密钥齐备)。
4
- * 根字段可空:取数失败只让该字段为 null(形状见 api/index.ts 的 RuntimeBootFacts),各领域按降级处理。
4
+ * HTTP 独立领域结果映射为内部可空事实;单域读取失败不影响其他域。
5
5
  */
6
- export type RuntimeModel = NonNullable<RuntimeBootQuery['runtimeModels']>[number];
6
+ export type RuntimeModel = NonNullable<BootFacts['runtimeModels']>[number];
7
7
  export type RuntimeConnection = RuntimeModel['connection'];
8
8
  /** 本次可读项目 + 其生效绑定(模型引用已按可用目录校验,失效为 null)。 */
9
- export type RuntimeProject = NonNullable<RuntimeWorkspaceProjectsQuery['runtimeProjects']>[number];
10
- export type RuntimeModelCredential = NonNullable<RuntimeBootQuery['runtimeModelCredentials']>[number];
9
+ export type RuntimeProject = NonNullable<WorkspaceFacts['runtimeProjects']>[number];
10
+ export type RuntimeModelCredential = NonNullable<BootFacts['runtimeModelCredentials']>[number];
11
11
  export type { InputModality, ModelProtocol, ReasoningLevel };
12
12
  /** dsh 通用 provider 的 api 适配器(`llm-pi-ai.providers[].api`)。 */
13
13
  export type ProviderApi = 'openai-completions' | 'openai-responses' | 'anthropic-messages';
@@ -1,12 +1,14 @@
1
1
  import type { Context } from '@deepseek-ai/cordis';
2
2
  import z from '@deepseek-ai/schemastery';
3
- export type { RuntimeProject, } from './hub/compile.ts';
4
- export type { RuntimeIdentity, RuntimeSkillFact, RuntimeSkillFileContentFact, RuntimeSkillFileFact, Semi2ConfigState, } from './hub/facts.ts';
5
- export type { ConfigStatus, Semi2Config, Semi2Audit, Semi2Health, Semi2Session, } from './service/config-service.ts';
3
+ export type { RuntimeProject } from './hub/compile.ts';
4
+ export type { RuntimeIdentity, RuntimeSkillFact, RuntimeSkillFileContentFact, RuntimeSkillFileFact, Semi2ConfigState } from './hub/facts.ts';
5
+ export type { ConfigStatus, Semi2Config, Semi2Audit, Semi2Health, Semi2Session } from './service/config-service.ts';
6
6
  export type { HeadlessModelOutcome } from './domains/types.ts';
7
7
  export type { Semi2PlatformKind } from './hub/facts.ts';
8
- export { SEMI2_RUNTIME_SERVICE, SEMI2_SECTION_ORDERS, runtimeFromCnbEnv, semi2SectionOrder, } from './contract.ts';
9
- export type { SectionOrderSource, Semi2Credentials, Semi2Platform, Semi2Runtime, Semi2SectionKey, } from './contract.ts';
8
+ export { SEMI2_RUNTIME_SERVICE, SEMI2_SECTION_ORDERS, runtimeFromCnbEnv, semi2SectionOrder } from './contract.ts';
9
+ export { cnbTokenPath, writeCnbSessionToken } from './cnb-token.ts';
10
+ export type { CnbTokenOptions, CnbTokenOutcome } from './cnb-token.ts';
11
+ export type { SectionOrderSource, Semi2Credentials, Semi2Platform, Semi2Runtime, Semi2SectionKey } from './contract.ts';
10
12
  import './events.ts';
11
13
  export declare const name = "semi2-dsh";
12
14
  /**
@@ -1,5 +1,5 @@
1
1
  import type { Context } from '@deepseek-ai/cordis';
2
- import { type Semi2Api } from '../api/index.ts';
2
+ import type { Semi2Api } from '../api/index.ts';
3
3
  import type { RuntimeEventReport } from '../api/index.ts';
4
4
  import type { DomainId, DomainPeers, HeadlessModelOutcome, HealthItem } from '../domains/types.ts';
5
5
  import type { Semi2ConfigState, Semi2PlatformKind } from '../hub/facts.ts';
@@ -33,9 +33,7 @@ function endpointOf(pathname) {
33
33
  }
34
34
  /** 动作分发:本地校验先于网络,失败一律回错误码信封,不抛。 */
35
35
  async function dispatch(runtime, endpoint, payload) {
36
- const body = payload !== null && typeof payload === 'object'
37
- ? payload
38
- : {};
36
+ const body = payload !== null && typeof payload === 'object' ? payload : {};
39
37
  try {
40
38
  if (endpoint === 'login') {
41
39
  const url = text(body.url);
package/lib/web/index.js CHANGED
@@ -16,7 +16,7 @@ export function installWebClient(ctx, runtime, registerHealth, options = {}) {
16
16
  return { state: 'unavailable', note: '本端无网页服务' };
17
17
  },
18
18
  });
19
- ctx.inject(['webServer'], (workstationCtx) => {
19
+ ctx.inject(['webServer'], workstationCtx => {
20
20
  const webServer = workstationCtx.get('webServer');
21
21
  surface = 'pending';
22
22
  const timer = setTimeout(() => {
@@ -35,7 +35,7 @@ export function installWebClient(ctx, runtime, registerHealth, options = {}) {
35
35
  });
36
36
  // 登录/退出/同步/健康路由经官方请求校验接口注册(`connection` 是 web 组合的必需条目):
37
37
  // 校验接口缺席就不装路由,由健康字段把这种情形暴露出来,而不是让路由静默失效。
38
- workstationCtx.inject(['connection'], (connCtx) => {
38
+ workstationCtx.inject(['connection'], connCtx => {
39
39
  surface = 'ready';
40
40
  const connection = connCtx.get('connection');
41
41
  installActionRoutes(connCtx, webServer, runtime, connection);
@@ -40,15 +40,16 @@ function warn(ctx, message) {
40
40
  }
41
41
  /** 在可选 `settings` 服务上 best-effort 预置:只降级。 */
42
42
  export function installWelcomeAck(ctx) {
43
- ctx.inject(['settings'], (settingsCtx) => {
44
- const settings = settingsCtx
45
- .get('settings');
43
+ ctx.inject(['settings'], settingsCtx => {
44
+ const settings = settingsCtx.get('settings');
46
45
  if (settings === undefined)
47
46
  return;
48
- void seedWelcomeAcknowledgement(settings).then((seeded) => {
47
+ void seedWelcomeAcknowledgement(settings)
48
+ .then(seeded => {
49
49
  if (!seeded)
50
50
  warn(ctx, 'ui-settings-general 段未就绪,跳过欢迎声明预置');
51
- }).catch((error) => {
51
+ })
52
+ .catch((error) => {
52
53
  warn(ctx, '写入 ui-settings-general 欢迎声明确认失败: ' + (error instanceof Error ? error.message : String(error)));
53
54
  });
54
55
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fa-software/semi2-dsh",
3
- "version": "0.0.18",
3
+ "version": "0.0.19-preview.20261001161030",
4
4
  "description": "Semi2 单插件:semi2-hub 配置引导 + 公共 Web 能力。",
5
5
  "homepage": "https://cnb.cool/fa-software/semi2/dsh/dsh-mono",
6
6
  "bugs": "https://cnb.cool/fa-software/semi2/dsh/dsh-mono/-/issues",
@@ -34,11 +34,9 @@
34
34
  "@deepseek-ai/dsh-client-ui-primitives": "^0.2.0-rc.1",
35
35
  "@deepseek-ai/dsh-llm": "^0.2.0-rc.1",
36
36
  "@fa-software/test-kit": "0.0.0",
37
- "@graphql-codegen/cli": "7.4.0",
38
- "@graphql-codegen/typescript-operations": "6.1.6",
39
37
  "@types/node": "^24.0.0",
40
38
  "@types/react": "^19.0.0",
41
- "graphql": "^16.11.0",
39
+ "openapi-typescript": "7.13.0",
42
40
  "react": "^19.2.0",
43
41
  "typescript": "~5.8.3",
44
42
  "vite-plus": "1.0.0"
@@ -105,7 +103,7 @@
105
103
  }
106
104
  },
107
105
  "scripts": {
108
- "build": "rm -rf lib && node scripts/gen-documents.ts && graphql-codegen -c codegen.ts && tsc -p tsconfig.json && vp pack",
106
+ "build": "rm -rf lib && node scripts/gen-http-types.ts && tsc -p tsconfig.json && vp pack",
109
107
  "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p src/client/tsconfig.json && tsc -p scripts/tsconfig.json",
110
108
  "dev": "tsc -p tsconfig.json --watch --preserveWatchOutput",
111
109
  "dev:client": "vp pack --watch"
package/lib/api/client.js DELETED
@@ -1,119 +0,0 @@
1
- // @fa-software/semi2-dsh/api/client —— GraphQL 传输唯一实现(全仓唯一网络出口的操作入口在 api/index.ts)。
2
- // 错误码一律取 `errors[].extensions.code`(GraphQL 通路恒 HTTP 200);操作文本来自生成的 api/generated/documents.ts。
3
- import { ConfigurationError } from "../hub/errors.js";
4
- /** 连接令牌形状:hub 接入密钥(cnbk_)、部署目录运行令牌(semi2_)或用户密钥(JWT 三段形态)。 */
5
- const TOKEN_SHAPE = /^(?:cnbk_[A-Za-z0-9_-]+|semi2_[A-Za-z0-9_-]+|[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+)$/;
6
- const REQUEST_TIMEOUT_MS = 15_000;
7
- const MAX_RESPONSE_BYTES = 2 * 1024 * 1024;
8
- /** semi2-hub 根地址:生产/预览都是 https;development 下额外放行回环 http。 */
9
- export function consoleEndpoint(value, nodeEnv) {
10
- let endpoint;
11
- try {
12
- endpoint = new URL(value.trim());
13
- }
14
- catch {
15
- throw new ConfigurationError('INVALID_CONFIG_URL');
16
- }
17
- const loopback = endpoint.hostname === 'localhost' ||
18
- endpoint.hostname === '[::1]' ||
19
- /^127(?:\.\d{1,3}){3}$/.test(endpoint.hostname);
20
- if (endpoint.username ||
21
- endpoint.password ||
22
- endpoint.search ||
23
- endpoint.hash ||
24
- (endpoint.protocol !== 'https:' &&
25
- !(endpoint.protocol === 'http:' && nodeEnv !== 'production' && loopback))) {
26
- throw new ConfigurationError('INVALID_CONFIG_URL');
27
- }
28
- endpoint.pathname = `${endpoint.pathname.replace(/\/+$/, '')}/graphql`;
29
- return endpoint;
30
- }
31
- function asRecord(value) {
32
- return value === null || typeof value !== 'object' || Array.isArray(value)
33
- ? null
34
- : value;
35
- }
36
- function errorCodeOf(payload) {
37
- const errors = payload.errors;
38
- if (!Array.isArray(errors))
39
- return null;
40
- for (const entry of errors) {
41
- const code = asRecord(asRecord(entry)?.extensions)?.code;
42
- if (typeof code === 'string' && code !== '')
43
- return code;
44
- }
45
- return null;
46
- }
47
- /** 流式累计,超 2MB 判失败;不把上游内容带进错误。 */
48
- async function readPayload(response) {
49
- const body = response.body;
50
- if (body === null)
51
- throw new ConfigurationError('CONFIG_REQUEST_FAILED');
52
- const chunks = [];
53
- let size = 0;
54
- for await (const chunk of body) {
55
- if (!(chunk instanceof Uint8Array))
56
- throw new ConfigurationError('CONFIG_REQUEST_FAILED');
57
- size += chunk.byteLength;
58
- if (size > MAX_RESPONSE_BYTES)
59
- throw new ConfigurationError('CONFIG_REQUEST_FAILED');
60
- chunks.push(chunk);
61
- }
62
- let parsed;
63
- try {
64
- parsed = JSON.parse(Buffer.concat(chunks).toString('utf8'));
65
- }
66
- catch {
67
- throw new ConfigurationError('CONFIG_REQUEST_FAILED');
68
- }
69
- const payload = asRecord(parsed);
70
- if (payload === null)
71
- throw new ConfigurationError('CONFIG_REQUEST_FAILED');
72
- return payload;
73
- }
74
- /**
75
- * 传输层失败抛 `ConfigurationError`;服务端领域失败回落在返回值的 errorCode 上(HTTP 200 +
76
- * `errors[].extensions.code`),由调用方决定降级。
77
- */
78
- export async function postGraphql(client, request) {
79
- const token = client.token.trim();
80
- if (token === '' || token.length > 512 || !TOKEN_SHAPE.test(token))
81
- throw new ConfigurationError('MISSING_ACCESS_TOKEN');
82
- const fetchImpl = client.fetchImpl ?? fetch;
83
- let response;
84
- try {
85
- response = await fetchImpl(client.endpoint, {
86
- method: 'POST',
87
- headers: {
88
- 'content-type': 'application/json',
89
- authorization: `Bearer ${token}`,
90
- 'cache-control': 'no-store',
91
- ...(client.creator === undefined
92
- ? {}
93
- : { 'x-semi2-cnb-creator': client.creator }),
94
- ...(client.channel === undefined ? {} : { 'x-semi2-channel': client.channel }),
95
- },
96
- cache: 'no-store',
97
- redirect: 'error',
98
- signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
99
- body: JSON.stringify({
100
- operationName: request.operationName,
101
- query: request.document,
102
- ...(request.variables === undefined
103
- ? {}
104
- : { variables: request.variables }),
105
- }),
106
- });
107
- }
108
- catch {
109
- throw new ConfigurationError('CONFIG_REQUEST_FAILED');
110
- }
111
- if (!response.ok)
112
- throw new ConfigurationError(response.status === 401 ? 'UNAUTHENTICATED' : 'CONFIG_REQUEST_FAILED');
113
- const payload = await readPayload(response);
114
- const data = payload.data;
115
- return {
116
- data: data === null || data === undefined ? null : data,
117
- errorCode: errorCodeOf(payload),
118
- };
119
- }