@xfey/tutti 0.1.119 → 0.1.120

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 (110) hide show
  1. package/dist/approvals/decision-command.d.ts +2 -2
  2. package/dist/collaboration-state/clarification-snapshot.d.ts +9 -9
  3. package/dist/collaboration-state/task-compile-context.d.ts +1 -1
  4. package/dist/control-plane/workflows/openai.d.ts +3 -4
  5. package/dist/control-plane/workflows/openai.js +3 -2
  6. package/dist/providers/openai/app-server/invocation-coordinator.d.ts +1 -0
  7. package/dist/providers/openai/app-server/invocation-coordinator.js +4 -1
  8. package/dist/providers/openai/app-server/invocation-deadline.d.ts +3 -0
  9. package/dist/providers/openai/app-server/invocation-deadline.js +15 -0
  10. package/dist/providers/openai/app-server/read-only-procedure.d.ts +4 -2
  11. package/dist/providers/openai/app-server/read-only-procedure.js +16 -0
  12. package/dist/providers/openai/app-server/workspace-write-run.d.ts +4 -2
  13. package/dist/providers/openai/app-server/workspace-write-run.js +16 -0
  14. package/dist/providers/openai/chat-assistant.d.ts +3 -4
  15. package/dist/providers/openai/chat-assistant.js +2 -1
  16. package/dist/providers/openai/execution-access.d.ts +17 -0
  17. package/dist/providers/openai/execution-access.js +13 -0
  18. package/dist/providers/openai/sdk-procedure-runner.d.ts +2 -2
  19. package/dist/providers/openai/sdk-procedure-runner.js +17 -0
  20. package/dist/run-pipeline/artifact-applicability.d.ts +3 -4
  21. package/dist/run-pipeline/artifact-applicability.js +2 -1
  22. package/dist/run-pipeline/openai.d.ts +3 -4
  23. package/dist/run-pipeline/openai.js +3 -2
  24. package/dist/run-pipeline/task-run-invocation.js +6 -12
  25. package/dist/server-shell/cli/cli.js +3 -0
  26. package/dist/server-shell/cli/host-lifecycle.js +1 -0
  27. package/dist/server-shell/cli/host-server-runtime.d.ts +1 -0
  28. package/dist/server-shell/cli/host-server-runtime.js +83 -34
  29. package/dist/server-shell/cli/launch-command.js +1 -1
  30. package/dist/server-shell/cli/launch.d.ts +7 -3
  31. package/dist/server-shell/cli/launch.js +23 -4
  32. package/dist/server-shell/cli/machine-local.d.ts +9 -0
  33. package/dist/server-shell/cli/machine-local.js +60 -6
  34. package/dist/server-shell/cli/project-resolver.d.ts +2 -2
  35. package/dist/server-shell/cli/project-resolver.js +6 -3
  36. package/dist/server-shell/cli/relay-registration.js +38 -1
  37. package/dist/server-shell/http/routes/local-control.d.ts +1 -1
  38. package/dist/server-shell/http/routes/local-control.js +2 -46
  39. package/dist/server-shell/http/routes/project-api/openapi-workspace-routes.d.ts +47 -137
  40. package/dist/server-shell/http/routes/project-api/openapi.d.ts +47 -137
  41. package/dist/server-shell/http/routes/project-api/schemas.d.ts +25 -136
  42. package/dist/server-shell/http/routes/project-api/schemas.js +4 -58
  43. package/dist/server-shell/http/routes/project-api/types.d.ts +4 -0
  44. package/dist/server-shell/local-console/managed-project-routes.d.ts +9 -0
  45. package/dist/server-shell/local-console/managed-project-routes.js +120 -0
  46. package/dist/server-shell/local-console/managed-project-service.d.ts +151 -0
  47. package/dist/server-shell/local-console/managed-project-service.js +163 -0
  48. package/dist/server-shell/local-console/operation-coordinator.d.ts +1 -1
  49. package/dist/server-shell/local-console/package-update-hosts.js +2 -1
  50. package/dist/server-shell/local-console/project-service.d.ts +5 -1
  51. package/dist/server-shell/local-console/project-service.js +63 -14
  52. package/dist/server-shell/local-console/server.js +22 -2
  53. package/dist/server-shell/managed-access/execution-binding.d.ts +9 -0
  54. package/dist/server-shell/managed-access/execution-binding.js +22 -0
  55. package/dist/server-shell/managed-access/existing-project.d.ts +15 -0
  56. package/dist/server-shell/managed-access/existing-project.js +41 -0
  57. package/dist/server-shell/managed-access/model-control-client.d.ts +66 -0
  58. package/dist/server-shell/managed-access/model-control-client.js +114 -0
  59. package/dist/server-shell/managed-access/private-store.d.ts +19 -0
  60. package/dist/server-shell/managed-access/private-store.js +275 -0
  61. package/dist/server-shell/managed-access/project-provider.d.ts +18 -0
  62. package/dist/server-shell/managed-access/project-provider.js +30 -0
  63. package/dist/server-shell/managed-access/records.d.ts +108 -0
  64. package/dist/server-shell/managed-access/records.js +73 -0
  65. package/dist/server-shell/managed-access/runners.d.ts +11 -0
  66. package/dist/server-shell/managed-access/runners.js +103 -0
  67. package/dist/server-shell/managed-access/runtime-records.d.ts +110 -0
  68. package/dist/server-shell/managed-access/runtime-records.js +65 -0
  69. package/dist/server-shell/managed-access/runtime.d.ts +48 -0
  70. package/dist/server-shell/managed-access/runtime.js +301 -0
  71. package/dist/server-shell/managed-access/state.d.ts +54 -0
  72. package/dist/server-shell/managed-access/state.js +287 -0
  73. package/dist/server-shell/managed-access/transport.d.ts +48 -0
  74. package/dist/server-shell/managed-access/transport.js +38 -0
  75. package/dist/server-shell/managed-access/workspace.d.ts +10 -0
  76. package/dist/server-shell/managed-access/workspace.js +69 -0
  77. package/dist/server-shell/smoke/e2e-client.d.ts +8 -3
  78. package/dist/server-shell/smoke/e2e-client.js +11 -11
  79. package/node_modules/@tutti/relay-client/dist/host-control.d.ts +4 -1
  80. package/node_modules/@tutti/relay-client/dist/host-control.js +26 -3
  81. package/node_modules/@tutti/relay-client/dist/index.d.ts +1 -0
  82. package/node_modules/@tutti/relay-client/dist/index.js +1 -0
  83. package/node_modules/@tutti/relay-client/dist/project-authority.d.ts +75 -0
  84. package/node_modules/@tutti/relay-client/dist/project-authority.js +140 -0
  85. package/node_modules/@tutti/shared/dist/ids/index.d.ts +7 -0
  86. package/node_modules/@tutti/shared/dist/ids/index.js +7 -0
  87. package/node_modules/@tutti/shared/dist/schemas/api/index.d.ts +1 -0
  88. package/node_modules/@tutti/shared/dist/schemas/api/index.js +1 -0
  89. package/node_modules/@tutti/shared/dist/schemas/api/managed-account.d.ts +35 -0
  90. package/node_modules/@tutti/shared/dist/schemas/api/managed-account.js +41 -0
  91. package/node_modules/@tutti/shared/dist/schemas/api/provider-config.d.ts +8 -4
  92. package/node_modules/@tutti/shared/dist/schemas/api/provider-config.js +6 -0
  93. package/node_modules/@tutti/shared/dist/schemas/api/runtime-events.d.ts +4 -0
  94. package/node_modules/@tutti/shared/dist/schemas/internal/creation-validation.d.ts +28 -0
  95. package/node_modules/@tutti/shared/dist/schemas/internal/creation-validation.js +42 -0
  96. package/node_modules/@tutti/shared/dist/schemas/internal/index.d.ts +5 -0
  97. package/node_modules/@tutti/shared/dist/schemas/internal/index.js +5 -0
  98. package/node_modules/@tutti/shared/dist/schemas/internal/managed-account.d.ts +12 -0
  99. package/node_modules/@tutti/shared/dist/schemas/internal/managed-account.js +13 -0
  100. package/node_modules/@tutti/shared/dist/schemas/internal/managed-models.d.ts +17 -0
  101. package/node_modules/@tutti/shared/dist/schemas/internal/managed-models.js +17 -0
  102. package/node_modules/@tutti/shared/dist/schemas/internal/managed-runtime.d.ts +116 -0
  103. package/node_modules/@tutti/shared/dist/schemas/internal/managed-runtime.js +87 -0
  104. package/node_modules/@tutti/shared/dist/schemas/internal/project-authority.d.ts +120 -0
  105. package/node_modules/@tutti/shared/dist/schemas/internal/project-authority.js +110 -0
  106. package/package.json +1 -1
  107. package/web/assets/{homepage-motion-scene-B6lCCHBq.js → homepage-motion-scene-DyMFsYmT.js} +1 -1
  108. package/web/assets/index-DSlecDXC.js +70 -0
  109. package/web/index.html +1 -1
  110. package/web/assets/index-DepsYMLl.js +0 -70
@@ -43,73 +43,7 @@ export declare const AccountAvatarProjectionSchema: {
43
43
  };
44
44
  }];
45
45
  };
46
- export declare const ProviderConfigProjectionSchema: {
47
- readonly oneOf: readonly [{
48
- readonly type: "object";
49
- readonly required: readonly ["status"];
50
- readonly additionalProperties: false;
51
- readonly properties: {
52
- readonly status: {
53
- readonly type: "string";
54
- readonly enum: readonly ["not_configured"];
55
- };
56
- };
57
- }, {
58
- readonly type: "object";
59
- readonly required: readonly ["status", "provider", "auth_kind", "redacted_key", "default_model", "validated_at"];
60
- readonly additionalProperties: false;
61
- readonly properties: {
62
- readonly status: {
63
- readonly type: "string";
64
- readonly enum: readonly ["configured"];
65
- };
66
- readonly provider: {
67
- readonly type: "string";
68
- readonly enum: readonly ["openai"];
69
- };
70
- readonly auth_kind: {
71
- readonly type: "string";
72
- readonly enum: readonly ["api_key"];
73
- };
74
- readonly redacted_key: {
75
- readonly type: "string";
76
- };
77
- readonly default_model: {
78
- readonly type: "string";
79
- };
80
- readonly validated_at: import("@sinclair/typebox").TString;
81
- };
82
- }, {
83
- readonly type: "object";
84
- readonly required: readonly ["status"];
85
- readonly additionalProperties: false;
86
- readonly properties: {
87
- readonly status: {
88
- readonly type: "string";
89
- readonly enum: readonly ["invalid"];
90
- };
91
- readonly provider: {
92
- readonly type: "string";
93
- readonly enum: readonly ["openai"];
94
- };
95
- readonly auth_kind: {
96
- readonly type: "string";
97
- readonly enum: readonly ["api_key"];
98
- };
99
- readonly redacted_key: {
100
- readonly type: "string";
101
- };
102
- readonly default_model: {
103
- readonly type: "string";
104
- };
105
- readonly validated_at: import("@sinclair/typebox").TString;
106
- readonly invalid_reason_code: {
107
- readonly type: "string";
108
- readonly enum: readonly ["provider_auth_invalid", "provider_quota_or_billing_required", "provider_rate_limited", "provider_model_unavailable", "provider_network_error", "unknown"];
109
- };
110
- };
111
- }];
112
- };
46
+ export { ProviderConfigProjectionSchema } from "@tutti/shared/schemas/api";
113
47
  export declare const ProviderUsageProjectionSchema: {
114
48
  readonly type: "object";
115
49
  readonly required: readonly ["total_tokens", "totals", "by_source", "by_model", "recent_windows"];
@@ -552,7 +486,7 @@ export declare const WorkspaceResponseSchema: {
552
486
  readonly properties: {
553
487
  readonly status: {
554
488
  readonly type: "string";
555
- readonly enum: readonly ["not_configured", "configured", "invalid"];
489
+ readonly enum: readonly ["not_configured", "configured", "managed", "invalid"];
556
490
  };
557
491
  readonly provider: {
558
492
  readonly type: "string";
@@ -735,7 +669,7 @@ export declare const BootstrapResponseSchema: {
735
669
  readonly properties: {
736
670
  readonly status: {
737
671
  readonly type: "string";
738
- readonly enum: readonly ["not_configured", "configured", "invalid"];
672
+ readonly enum: readonly ["not_configured", "configured", "managed", "invalid"];
739
673
  };
740
674
  readonly provider: {
741
675
  readonly type: "string";
@@ -873,73 +807,28 @@ export declare const BootstrapResponseSchema: {
873
807
  };
874
808
  };
875
809
  };
876
- readonly provider_config: {
877
- readonly oneOf: readonly [{
878
- readonly type: "object";
879
- readonly required: readonly ["status"];
880
- readonly additionalProperties: false;
881
- readonly properties: {
882
- readonly status: {
883
- readonly type: "string";
884
- readonly enum: readonly ["not_configured"];
885
- };
886
- };
887
- }, {
888
- readonly type: "object";
889
- readonly required: readonly ["status", "provider", "auth_kind", "redacted_key", "default_model", "validated_at"];
890
- readonly additionalProperties: false;
891
- readonly properties: {
892
- readonly status: {
893
- readonly type: "string";
894
- readonly enum: readonly ["configured"];
895
- };
896
- readonly provider: {
897
- readonly type: "string";
898
- readonly enum: readonly ["openai"];
899
- };
900
- readonly auth_kind: {
901
- readonly type: "string";
902
- readonly enum: readonly ["api_key"];
903
- };
904
- readonly redacted_key: {
905
- readonly type: "string";
906
- };
907
- readonly default_model: {
908
- readonly type: "string";
909
- };
910
- readonly validated_at: import("@sinclair/typebox").TString;
911
- };
912
- }, {
913
- readonly type: "object";
914
- readonly required: readonly ["status"];
915
- readonly additionalProperties: false;
916
- readonly properties: {
917
- readonly status: {
918
- readonly type: "string";
919
- readonly enum: readonly ["invalid"];
920
- };
921
- readonly provider: {
922
- readonly type: "string";
923
- readonly enum: readonly ["openai"];
924
- };
925
- readonly auth_kind: {
926
- readonly type: "string";
927
- readonly enum: readonly ["api_key"];
928
- };
929
- readonly redacted_key: {
930
- readonly type: "string";
931
- };
932
- readonly default_model: {
933
- readonly type: "string";
934
- };
935
- readonly validated_at: import("@sinclair/typebox").TString;
936
- readonly invalid_reason_code: {
937
- readonly type: "string";
938
- readonly enum: readonly ["provider_auth_invalid", "provider_quota_or_billing_required", "provider_rate_limited", "provider_model_unavailable", "provider_network_error", "unknown"];
939
- };
940
- };
941
- }];
942
- };
810
+ readonly provider_config: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
811
+ status: import("@sinclair/typebox").TLiteral<"not_configured">;
812
+ }>, import("@sinclair/typebox").TObject<{
813
+ status: import("@sinclair/typebox").TLiteral<"managed">;
814
+ funding_kind: import("@sinclair/typebox").TLiteral<"trial">;
815
+ tier: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"light">, import("@sinclair/typebox").TLiteral<"high">, import("@sinclair/typebox").TLiteral<"max">]>;
816
+ }>, import("@sinclair/typebox").TObject<{
817
+ status: import("@sinclair/typebox").TLiteral<"configured">;
818
+ provider: import("@sinclair/typebox").TLiteral<"openai">;
819
+ auth_kind: import("@sinclair/typebox").TLiteral<"api_key">;
820
+ redacted_key: import("@sinclair/typebox").TString;
821
+ default_model: import("@sinclair/typebox").TString;
822
+ validated_at: import("@sinclair/typebox").TString;
823
+ }>, import("@sinclair/typebox").TObject<{
824
+ status: import("@sinclair/typebox").TLiteral<"invalid">;
825
+ provider: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TLiteral<"openai">>;
826
+ auth_kind: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TLiteral<"api_key">>;
827
+ redacted_key: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
828
+ default_model: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
829
+ validated_at: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
830
+ invalid_reason_code: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"provider_auth_invalid">, import("@sinclair/typebox").TLiteral<"provider_quota_or_billing_required">, import("@sinclair/typebox").TLiteral<"provider_rate_limited">, import("@sinclair/typebox").TLiteral<"provider_model_unavailable">, import("@sinclair/typebox").TLiteral<"provider_network_error">, import("@sinclair/typebox").TLiteral<"unknown">]>>;
831
+ }>]>;
943
832
  readonly snapshots: {
944
833
  readonly type: "object";
945
834
  readonly additionalProperties: false;
@@ -1,5 +1,5 @@
1
1
  import { ApprovalRequestIdSchema, ClarificationRoundRefSchema, ClarificationThreadRefSchema, IdempotencyKeySchema, IsoDateTimeStringSchema, ProjectIdSchema, RelayAccountRefSchema, RelayClientSessionIdSchema, RelayPlatformSessionRefSchema, RelayProjectRefSchema, RecoverySummaryIdSchema, TaskIdSchema, } from "@tutti/shared/schemas/domain";
2
- import { ActiveClarificationProjectionSchema, ActiveApprovalProjectionSchema, ExecutionStatusProjectionSchema, MessageWindowSchema, ProjectTimelineResponseSchema, ReadStateSummaryProjectionSchema, ScratchpadProjectionSchema, WorklistProjectionSchema, } from "@tutti/shared/schemas/api";
2
+ import { ActiveClarificationProjectionSchema, ActiveApprovalProjectionSchema, ExecutionStatusProjectionSchema, MessageWindowSchema, ProjectTimelineResponseSchema, ReadStateSummaryProjectionSchema, ScratchpadProjectionSchema, WorklistProjectionSchema, ProviderConfigProjectionSchema, } from "@tutti/shared/schemas/api";
3
3
  import { ACCOUNT_AVATAR_COLORS } from "@tutti/shared/domain";
4
4
  import { HOST_MAINLINE_BRANCH } from "./constants.js";
5
5
  export const AccountAvatarProjectionSchema = {
@@ -27,62 +27,8 @@ export const AccountAvatarProjectionSchema = {
27
27
  },
28
28
  ],
29
29
  };
30
- export const ProviderConfigProjectionSchema = {
31
- oneOf: [
32
- {
33
- type: "object",
34
- required: ["status"],
35
- additionalProperties: false,
36
- properties: {
37
- status: { type: "string", enum: ["not_configured"] },
38
- },
39
- },
40
- {
41
- type: "object",
42
- required: [
43
- "status",
44
- "provider",
45
- "auth_kind",
46
- "redacted_key",
47
- "default_model",
48
- "validated_at",
49
- ],
50
- additionalProperties: false,
51
- properties: {
52
- status: { type: "string", enum: ["configured"] },
53
- provider: { type: "string", enum: ["openai"] },
54
- auth_kind: { type: "string", enum: ["api_key"] },
55
- redacted_key: { type: "string" },
56
- default_model: { type: "string" },
57
- validated_at: IsoDateTimeStringSchema,
58
- },
59
- },
60
- {
61
- type: "object",
62
- required: ["status"],
63
- additionalProperties: false,
64
- properties: {
65
- status: { type: "string", enum: ["invalid"] },
66
- provider: { type: "string", enum: ["openai"] },
67
- auth_kind: { type: "string", enum: ["api_key"] },
68
- redacted_key: { type: "string" },
69
- default_model: { type: "string" },
70
- validated_at: IsoDateTimeStringSchema,
71
- invalid_reason_code: {
72
- type: "string",
73
- enum: [
74
- "provider_auth_invalid",
75
- "provider_quota_or_billing_required",
76
- "provider_rate_limited",
77
- "provider_model_unavailable",
78
- "provider_network_error",
79
- "unknown",
80
- ],
81
- },
82
- },
83
- },
84
- ],
85
- };
30
+ // Keep Fastify serialization and OpenAPI on the shared provider contract.
31
+ export { ProviderConfigProjectionSchema } from "@tutti/shared/schemas/api";
86
32
  const ProviderUsageBreakdownProjectionSchema = {
87
33
  type: "object",
88
34
  required: [
@@ -305,7 +251,7 @@ export const WorkspaceResponseSchema = {
305
251
  required: ["status"],
306
252
  additionalProperties: false,
307
253
  properties: {
308
- status: { type: "string", enum: ["not_configured", "configured", "invalid"] },
254
+ status: { type: "string", enum: ["not_configured", "configured", "managed", "invalid"] },
309
255
  provider: { type: "string", enum: ["openai"] },
310
256
  },
311
257
  },
@@ -23,6 +23,10 @@ export type ResolvedStagedUpload = {
23
23
  complete: (status: "completed" | "aborted") => Promise<void>;
24
24
  };
25
25
  export type HostProviderConfigProjection = {
26
+ status: "managed";
27
+ funding_kind: "trial";
28
+ tier: "light" | "high" | "max";
29
+ } | {
26
30
  status: "not_configured";
27
31
  } | {
28
32
  status: "configured";
@@ -0,0 +1,9 @@
1
+ import type { FastifyInstance, FastifyRequest } from "fastify";
2
+ import { type LocalConsoleManagedProjectService } from "./managed-project-service.js";
3
+ import type { ReadLocalConsoleSession } from "./session.js";
4
+ export declare function registerLocalConsoleManagedProjectRoutes(app: FastifyInstance, options: {
5
+ service: LocalConsoleManagedProjectService;
6
+ tuttiHome: string;
7
+ requireSession: (request: FastifyRequest, csrf: boolean) => ReadLocalConsoleSession;
8
+ }): void;
9
+ //# sourceMappingURL=managed-project-routes.d.ts.map
@@ -0,0 +1,120 @@
1
+ import { Type } from "@sinclair/typebox";
2
+ import { Value } from "@sinclair/typebox/value";
3
+ import { IdempotencyKeySchema } from "@tutti/shared/schemas/domain";
4
+ import { serializeRuntimeLogLine } from "@tutti/shared/utils";
5
+ import { NativeAuthorityTransportError } from "@tutti/relay-client";
6
+ import { appendHostLogLine, getHostLogFilePath } from "../cli/machine-local.js";
7
+ import { ManagedLocalStateError } from "../managed-access/private-store.js";
8
+ import { LocalConsoleProjectError } from "./project-service.js";
9
+ import { LocalConsoleOperationConflictError } from "./operation-coordinator.js";
10
+ import { LaunchError } from "../cli/errors.js";
11
+ import { ManagedDraftInputSchema, } from "./managed-project-service.js";
12
+ const ReadSchema = Type.Object({ request_ref: IdempotencyKeySchema }, { additionalProperties: false });
13
+ export function registerLocalConsoleManagedProjectRoutes(app, options) {
14
+ for (const operation of ["prepare", "read", "reconcile", "validate", "launch"]) {
15
+ app.post(`/local-console/v1/managed-projects/${operation}`, {
16
+ bodyLimit: 8192,
17
+ errorHandler: (error, request, reply) => {
18
+ if (error.code !== "FST_ERR_CTP_INVALID_JSON_BODY" &&
19
+ error.code !== "FST_ERR_CTP_BODY_TOO_LARGE")
20
+ throw error;
21
+ const status = error.code === "FST_ERR_CTP_BODY_TOO_LARGE" ? 413 : 400;
22
+ void reply
23
+ .code(status)
24
+ .header("cache-control", "no-store")
25
+ .header("x-tutti-request-id", request.id)
26
+ .send({
27
+ error: {
28
+ code: status === 413 ? "payload_too_large" : "managed_creation_input_invalid",
29
+ request_id: request.id,
30
+ retryable: false,
31
+ },
32
+ });
33
+ },
34
+ onError: (request, _reply, error, done) => {
35
+ // Parser, loopback, cookie and CSRF rejection precede the operation handler.
36
+ // Never record error.message: JSON parser errors may include request content.
37
+ observeManagedCreation(options.tuttiHome, request.id, operation, "rejected", error.statusCode === 401
38
+ ? "session_required"
39
+ : error.statusCode === 403
40
+ ? "request_origin_or_csrf_rejected"
41
+ : error.statusCode === 413
42
+ ? "payload_too_large"
43
+ : "managed_http_rejected");
44
+ done();
45
+ },
46
+ }, async (request, reply) => {
47
+ const diagnostic = request.id;
48
+ reply.header("x-tutti-request-id", diagnostic);
49
+ const session = options.requireSession(request, true);
50
+ if (!session.accountReady) {
51
+ observeManagedCreation(options.tuttiHome, diagnostic, operation, "rejected", "account_required");
52
+ return reply.code(401).send({
53
+ error: { code: "account_required", request_id: diagnostic, retryable: false },
54
+ });
55
+ }
56
+ const observe = (status, reason, upstreamRequestId) => {
57
+ observeManagedCreation(options.tuttiHome, diagnostic, operation, status, reason, upstreamRequestId);
58
+ };
59
+ try {
60
+ if (Object.keys(request.query).length)
61
+ throw new ManagedLocalStateError("managed_creation_input_invalid");
62
+ let result;
63
+ if (operation === "prepare") {
64
+ if (!Value.Check(ManagedDraftInputSchema, request.body))
65
+ throw new ManagedLocalStateError("managed_creation_input_invalid");
66
+ result = await options.service.prepare(request.body, session.context);
67
+ }
68
+ else {
69
+ if (!Value.Check(ReadSchema, request.body))
70
+ throw new ManagedLocalStateError("managed_creation_input_invalid");
71
+ result = await options.service[operation](request.body.request_ref, session.context);
72
+ }
73
+ observe("succeeded");
74
+ return result;
75
+ }
76
+ catch (error) {
77
+ const code = error instanceof ManagedLocalStateError ||
78
+ error instanceof LocalConsoleProjectError ||
79
+ error instanceof LocalConsoleOperationConflictError ||
80
+ error instanceof LaunchError ||
81
+ error instanceof NativeAuthorityTransportError
82
+ ? error.code
83
+ : "managed_creation_unavailable";
84
+ const status = error instanceof NativeAuthorityTransportError
85
+ ? (error.status ?? 503)
86
+ : error instanceof LocalConsoleProjectError
87
+ ? error.statusCode
88
+ : code === "managed_creation_input_invalid"
89
+ ? 400
90
+ : 409;
91
+ observe("rejected", code, error instanceof NativeAuthorityTransportError ? error.requestId : undefined);
92
+ return reply
93
+ .code(status)
94
+ .send({ error: { code, request_id: diagnostic, retryable: false } });
95
+ }
96
+ });
97
+ }
98
+ }
99
+ function observeManagedCreation(tuttiHome, diagnostic, stage, status, reason, upstreamRequestId) {
100
+ try {
101
+ appendHostLogLine(getHostLogFilePath(tuttiHome), serializeRuntimeLogLine({
102
+ service: "host",
103
+ component: "managed-creation",
104
+ level: status === "succeeded" ? "info" : "warn",
105
+ message: "Native managed creation operation",
106
+ fields: {
107
+ request_id: diagnostic,
108
+ stage,
109
+ status,
110
+ ...(reason === undefined ? {} : { reason_code: reason }),
111
+ ...(upstreamRequestId === undefined ? {} : { relay_request_id: upstreamRequestId }),
112
+ },
113
+ now: () => new Date(),
114
+ }));
115
+ }
116
+ catch {
117
+ /* Diagnostics cannot alter authorization or disclose private failures. */
118
+ }
119
+ }
120
+ //# sourceMappingURL=managed-project-routes.js.map
@@ -0,0 +1,151 @@
1
+ import { type Static } from "@sinclair/typebox";
2
+ import { type LocalConsoleInvocationContext } from "./invocation-context.js";
3
+ import type { LocalConsoleOperationCoordinator } from "./operation-coordinator.js";
4
+ import type { LocalConsoleProjectService } from "./project-service.js";
5
+ export declare const ManagedDraftInputSchema: import("@sinclair/typebox").TObject<{
6
+ request_ref: import("@sinclair/typebox").TString;
7
+ workspace_path: import("@sinclair/typebox").TString;
8
+ display_name: import("@sinclair/typebox").TString;
9
+ description: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
10
+ surface: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"standalone">, import("@sinclair/typebox").TLiteral<"feishu">]>;
11
+ tier: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"light">, import("@sinclair/typebox").TLiteral<"high">, import("@sinclair/typebox").TLiteral<"max">]>;
12
+ existing_project_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
13
+ }>;
14
+ export type ManagedDraftInput = Static<typeof ManagedDraftInputSchema>;
15
+ export declare class LocalConsoleManagedProjectService {
16
+ private readonly options;
17
+ constructor(options: {
18
+ tuttiHome: string;
19
+ operations: LocalConsoleOperationCoordinator;
20
+ serviceEnvironment?: NodeJS.ProcessEnv;
21
+ fetchImpl?: typeof fetch;
22
+ now?: () => Date;
23
+ projects?: Pick<LocalConsoleProjectService, "launchAuthorizedProject">;
24
+ });
25
+ private environment;
26
+ private state;
27
+ prepare(input: ManagedDraftInput, context: LocalConsoleInvocationContext): Promise<{
28
+ draft: {
29
+ state: "validation_failed" | "prepared" | "registered" | "validated" | "awaiting_authorization" | "validation_unknown";
30
+ expires_at: string;
31
+ existing_project_id?: `prj_${string}`;
32
+ surface: "standalone" | "feishu";
33
+ tier: "light" | "high" | "max";
34
+ description?: string;
35
+ request_ref: string;
36
+ project_id: `prj_${string}`;
37
+ display_name: string;
38
+ workspace_path: string;
39
+ };
40
+ relay_origin: string;
41
+ preparation: {
42
+ existing_relay_project_ref?: string;
43
+ expires_before?: string;
44
+ installation_ref: string;
45
+ surface: "standalone" | "feishu";
46
+ tier: "light" | "high" | "max";
47
+ request_ref: string;
48
+ project_id: string;
49
+ installation_secret_hash: string;
50
+ handoff_token_hash: string;
51
+ host_registration_secret_hash: string;
52
+ trial_consent: "trial-project-v1";
53
+ };
54
+ }>;
55
+ read(requestRef: string, context: LocalConsoleInvocationContext): {
56
+ draft: {
57
+ state: "validation_failed" | "prepared" | "registered" | "validated" | "awaiting_authorization" | "validation_unknown";
58
+ expires_at: string;
59
+ existing_project_id?: `prj_${string}`;
60
+ surface: "standalone" | "feishu";
61
+ tier: "light" | "high" | "max";
62
+ description?: string;
63
+ request_ref: string;
64
+ project_id: `prj_${string}`;
65
+ display_name: string;
66
+ workspace_path: string;
67
+ };
68
+ relay_origin: string;
69
+ preparation: {
70
+ existing_relay_project_ref?: string;
71
+ expires_before?: string;
72
+ installation_ref: string;
73
+ surface: "standalone" | "feishu";
74
+ tier: "light" | "high" | "max";
75
+ request_ref: string;
76
+ project_id: string;
77
+ installation_secret_hash: string;
78
+ handoff_token_hash: string;
79
+ host_registration_secret_hash: string;
80
+ trial_consent: "trial-project-v1";
81
+ };
82
+ };
83
+ reconcile(requestRef: string, context: LocalConsoleInvocationContext): Promise<{
84
+ draft: {
85
+ state: "validation_failed" | "prepared" | "registered" | "validated" | "awaiting_authorization" | "validation_unknown";
86
+ expires_at: string;
87
+ existing_project_id?: `prj_${string}`;
88
+ surface: "standalone" | "feishu";
89
+ tier: "light" | "high" | "max";
90
+ description?: string;
91
+ request_ref: string;
92
+ project_id: `prj_${string}`;
93
+ display_name: string;
94
+ workspace_path: string;
95
+ };
96
+ relay_origin: string;
97
+ preparation: {
98
+ existing_relay_project_ref?: string;
99
+ expires_before?: string;
100
+ installation_ref: string;
101
+ surface: "standalone" | "feishu";
102
+ tier: "light" | "high" | "max";
103
+ request_ref: string;
104
+ project_id: string;
105
+ installation_secret_hash: string;
106
+ handoff_token_hash: string;
107
+ host_registration_secret_hash: string;
108
+ trial_consent: "trial-project-v1";
109
+ };
110
+ }>;
111
+ validate(requestRef: string, context: LocalConsoleInvocationContext): Promise<{
112
+ validation: {
113
+ state: "failed" | "unknown" | "started" | "succeeded";
114
+ installation_ref: string;
115
+ tier: "light" | "high" | "max";
116
+ reason_code: "validation_started" | "validation_succeeded" | "validation_route_unavailable" | "validation_http_rejected" | "validation_response_invalid" | "validation_transport_unknown" | "validation_interrupted";
117
+ project_id: string;
118
+ creation_ref: string;
119
+ route_ref: string;
120
+ http_status: number | null;
121
+ };
122
+ draft: {
123
+ state: "validation_failed" | "prepared" | "registered" | "validated" | "awaiting_authorization" | "validation_unknown";
124
+ expires_at: string;
125
+ existing_project_id?: `prj_${string}`;
126
+ surface: "standalone" | "feishu";
127
+ tier: "light" | "high" | "max";
128
+ description?: string;
129
+ request_ref: string;
130
+ project_id: `prj_${string}`;
131
+ display_name: string;
132
+ workspace_path: string;
133
+ };
134
+ relay_origin: string;
135
+ preparation: {
136
+ existing_relay_project_ref?: string;
137
+ expires_before?: string;
138
+ installation_ref: string;
139
+ surface: "standalone" | "feishu";
140
+ tier: "light" | "high" | "max";
141
+ request_ref: string;
142
+ project_id: string;
143
+ installation_secret_hash: string;
144
+ handoff_token_hash: string;
145
+ host_registration_secret_hash: string;
146
+ trial_consent: "trial-project-v1";
147
+ };
148
+ }>;
149
+ launch(requestRef: string, context: LocalConsoleInvocationContext): Promise<import("./project-service.js").LocalConsoleLaunchResult>;
150
+ }
151
+ //# sourceMappingURL=managed-project-service.d.ts.map