@synsci/sdk 2.0.77 → 2.0.78-test.34098503148

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.
@@ -1904,6 +1904,7 @@ export class Session extends HeyApiClient {
1904
1904
  { in: "body", key: "parentID" },
1905
1905
  { in: "body", key: "title" },
1906
1906
  { in: "body", key: "permission" },
1907
+ { in: "body", key: "workspace" },
1907
1908
  ],
1908
1909
  },
1909
1910
  ]);
@@ -2586,7 +2587,16 @@ export class Runtime extends HeyApiClient {
2586
2587
  args: [
2587
2588
  { in: "query", key: "directory" },
2588
2589
  { in: "body", key: "sessionID" },
2590
+ { in: "body", key: "messageID" },
2591
+ { in: "body", key: "model" },
2592
+ { in: "body", key: "variant" },
2593
+ { in: "body", key: "tier" },
2594
+ { in: "body", key: "context" },
2595
+ { in: "body", key: "delegation" },
2596
+ { in: "body", key: "delegationSettings" },
2597
+ { in: "body", key: "requestID" },
2589
2598
  { in: "body", key: "message" },
2599
+ { in: "body", key: "parts" },
2590
2600
  { in: "body", key: "effort" },
2591
2601
  ],
2592
2602
  },
@@ -2602,6 +2612,109 @@ export class Runtime extends HeyApiClient {
2602
2612
  },
2603
2613
  });
2604
2614
  }
2615
+ /**
2616
+ * Cancel one research run
2617
+ *
2618
+ * Cancellation is scoped to the run ID. Repeating it cannot stop a later run. Running tools may need time to settle; read the run receipt for terminal state.
2619
+ */
2620
+ cancel(parameters, options) {
2621
+ const params = buildClientParams([parameters], [
2622
+ {
2623
+ args: [
2624
+ { in: "query", key: "directory" },
2625
+ { in: "body", key: "sessionID" },
2626
+ { in: "body", key: "runID" },
2627
+ ],
2628
+ },
2629
+ ]);
2630
+ return (options?.client ?? this.client).post({
2631
+ url: "/runtime/cancel",
2632
+ ...options,
2633
+ ...params,
2634
+ headers: {
2635
+ "Content-Type": "application/json",
2636
+ ...options?.headers,
2637
+ ...params.headers,
2638
+ },
2639
+ });
2640
+ }
2641
+ /**
2642
+ * Resolve a pending runtime decision
2643
+ *
2644
+ * Retries of an identical decision return its stored receipt. A conflicting response is rejected. Only live requests on the connected runtime can be resolved; an indeterminate receipt requires inspecting current state rather than repeating the action.
2645
+ */
2646
+ decide(parameters, options) {
2647
+ const params = buildClientParams([parameters], [
2648
+ {
2649
+ args: [
2650
+ { in: "query", key: "directory" },
2651
+ { key: "runtimeDecisionInput", map: "body" },
2652
+ ],
2653
+ },
2654
+ ]);
2655
+ return (options?.client ?? this.client).post({
2656
+ url: "/runtime/decision",
2657
+ ...options,
2658
+ ...params,
2659
+ headers: {
2660
+ "Content-Type": "application/json",
2661
+ ...options?.headers,
2662
+ ...params.headers,
2663
+ },
2664
+ });
2665
+ }
2666
+ /**
2667
+ * Get supported runtime protocol
2668
+ */
2669
+ capabilities(parameters, options) {
2670
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
2671
+ return (options?.client ?? this.client).get({
2672
+ url: "/runtime/capabilities",
2673
+ ...options,
2674
+ ...params,
2675
+ });
2676
+ }
2677
+ /**
2678
+ * Get a durable research run
2679
+ *
2680
+ * Returns the authoritative run receipt and terminal result reference, independently of event retention. A dead runtime is interrupted and never automatically retried.
2681
+ */
2682
+ getRun(parameters, options) {
2683
+ const params = buildClientParams([parameters], [
2684
+ {
2685
+ args: [
2686
+ { in: "query", key: "directory" },
2687
+ { in: "query", key: "sessionID" },
2688
+ { in: "query", key: "runID" },
2689
+ ],
2690
+ },
2691
+ ]);
2692
+ return (options?.client ?? this.client).get({
2693
+ url: "/runtime/run",
2694
+ ...options,
2695
+ ...params,
2696
+ });
2697
+ }
2698
+ /**
2699
+ * Resynchronize a research session
2700
+ *
2701
+ * Returns durable run receipts, an event cursor and live pending decisions belonging to this server process. Replayed decision events are historical; only pending requests in a fresh snapshot are actionable.
2702
+ */
2703
+ snapshot(parameters, options) {
2704
+ const params = buildClientParams([parameters], [
2705
+ {
2706
+ args: [
2707
+ { in: "query", key: "directory" },
2708
+ { in: "query", key: "sessionID" },
2709
+ ],
2710
+ },
2711
+ ]);
2712
+ return (options?.client ?? this.client).get({
2713
+ url: "/runtime/snapshot",
2714
+ ...options,
2715
+ ...params,
2716
+ });
2717
+ }
2605
2718
  /**
2606
2719
  * Replay research run events
2607
2720
  *
@@ -366,34 +366,6 @@ export type TextPart = {
366
366
  [key: string]: unknown;
367
367
  };
368
368
  };
369
- export type SubtaskPart = {
370
- id: string;
371
- sessionID: string;
372
- messageID: string;
373
- type: "subtask";
374
- prompt: string;
375
- description: string;
376
- agent: string;
377
- model?: {
378
- providerID: string;
379
- modelID: string;
380
- };
381
- command?: string;
382
- };
383
- export type ReasoningPart = {
384
- id: string;
385
- sessionID: string;
386
- messageID: string;
387
- type: "reasoning";
388
- text: string;
389
- metadata?: {
390
- [key: string]: unknown;
391
- };
392
- time: {
393
- start: number;
394
- end?: number;
395
- };
396
- };
397
369
  export type FilePartSourceText = {
398
370
  value: string;
399
371
  start: number;
@@ -429,6 +401,42 @@ export type ResourceSource = {
429
401
  uri: string;
430
402
  };
431
403
  export type FilePartSource = FileSource | SymbolSource | ResourceSource;
404
+ export type SubtaskAttachment = {
405
+ type: "file";
406
+ mime: string;
407
+ filename?: string;
408
+ url: string;
409
+ source?: FilePartSource;
410
+ };
411
+ export type SubtaskPart = {
412
+ id: string;
413
+ sessionID: string;
414
+ messageID: string;
415
+ type: "subtask";
416
+ prompt: string;
417
+ description: string;
418
+ agent: string;
419
+ model?: {
420
+ providerID: string;
421
+ modelID: string;
422
+ };
423
+ command?: string;
424
+ attachments?: Array<SubtaskAttachment>;
425
+ };
426
+ export type ReasoningPart = {
427
+ id: string;
428
+ sessionID: string;
429
+ messageID: string;
430
+ type: "reasoning";
431
+ text: string;
432
+ metadata?: {
433
+ [key: string]: unknown;
434
+ };
435
+ time: {
436
+ start: number;
437
+ end?: number;
438
+ };
439
+ };
432
440
  export type FilePart = {
433
441
  id: string;
434
442
  sessionID: string;
@@ -624,6 +632,13 @@ export type EventPermissionAsked = {
624
632
  type: "permission.asked";
625
633
  properties: PermissionRequest;
626
634
  };
635
+ export type EventPermissionCancelled = {
636
+ type: "permission.cancelled";
637
+ properties: {
638
+ sessionID: string;
639
+ requestID: string;
640
+ };
641
+ };
627
642
  export type EventPermissionReplied = {
628
643
  type: "permission.replied";
629
644
  properties: {
@@ -775,6 +790,13 @@ export type EventQuestionReplied = {
775
790
  answers: Array<QuestionAnswer>;
776
791
  };
777
792
  };
793
+ export type EventQuestionCancelled = {
794
+ type: "question.cancelled";
795
+ properties: {
796
+ sessionID: string;
797
+ requestID: string;
798
+ };
799
+ };
778
800
  export type EventQuestionRejected = {
779
801
  type: "question.rejected";
780
802
  properties: {
@@ -847,6 +869,10 @@ export type Session = {
847
869
  slug: string;
848
870
  projectID: string;
849
871
  directory: string;
872
+ /**
873
+ * Default tool directory: owned scratch or the existing project directory.
874
+ */
875
+ workspace?: "isolated" | "project";
850
876
  parentID?: string;
851
877
  summary?: {
852
878
  additions: number;
@@ -998,7 +1024,7 @@ export type EventWorktreeFailed = {
998
1024
  message: string;
999
1025
  };
1000
1026
  };
1001
- export type Event = EventServerConnected | EventGlobalDisposed | EventInstallationUpdated | EventInstallationUpdateAvailable | EventProjectUpdated | EventServerInstanceDisposed | EventProjectTrustChanged | EventAccountUpdated | EventLspClientDiagnostics | EventLspUpdated | EventFileWatcherUpdated | EventSessionFilesystemChanged | EventProjectAccessChanged | EventVcsBranchUpdated | EventMessageUpdated | EventMessageRemoved | EventMessagePartUpdated | EventMessagePartRemoved | EventPermissionAsked | EventPermissionReplied | EventSkillUpdated | EventSessionContext | EventSessionCompaction | EventSessionRequestProgress | EventSessionStatus | EventSessionIdle | EventQuestionAsked | EventQuestionReplied | EventQuestionRejected | EventSessionCompacted | EventTodoUpdated | EventMcpToolsChanged | EventMcpBrowserOpenFailed | EventCommandExecuted | EventSessionCreated | EventSessionUpdated | EventSessionDeleted | EventSessionDiff | EventSessionError | EventFileEdited | EventPtyCreated | EventPtyUpdated | EventPtyExited | EventPtyDeleted | EventWorktreeReady | EventWorktreeFailed;
1027
+ export type Event = EventServerConnected | EventGlobalDisposed | EventInstallationUpdated | EventInstallationUpdateAvailable | EventProjectUpdated | EventServerInstanceDisposed | EventProjectTrustChanged | EventAccountUpdated | EventLspClientDiagnostics | EventLspUpdated | EventFileWatcherUpdated | EventSessionFilesystemChanged | EventProjectAccessChanged | EventVcsBranchUpdated | EventMessageUpdated | EventMessageRemoved | EventMessagePartUpdated | EventMessagePartRemoved | EventPermissionAsked | EventPermissionCancelled | EventPermissionReplied | EventSkillUpdated | EventSessionContext | EventSessionCompaction | EventSessionRequestProgress | EventSessionStatus | EventSessionIdle | EventQuestionAsked | EventQuestionReplied | EventQuestionCancelled | EventQuestionRejected | EventSessionCompacted | EventTodoUpdated | EventMcpToolsChanged | EventMcpBrowserOpenFailed | EventCommandExecuted | EventSessionCreated | EventSessionUpdated | EventSessionDeleted | EventSessionDiff | EventSessionError | EventFileEdited | EventPtyCreated | EventPtyUpdated | EventPtyExited | EventPtyDeleted | EventWorktreeReady | EventWorktreeFailed;
1002
1028
  export type GlobalEvent = {
1003
1029
  directory: string;
1004
1030
  payload: Event;
@@ -2139,11 +2165,68 @@ export type SubtaskPartInput = {
2139
2165
  modelID: string;
2140
2166
  };
2141
2167
  command?: string;
2168
+ attachments?: Array<SubtaskAttachment>;
2142
2169
  };
2143
2170
  export type RuntimePromptAccepted = {
2144
2171
  runID: string;
2145
2172
  acceptedAt: number;
2146
2173
  };
2174
+ export type RuntimeRun = {
2175
+ runID: string;
2176
+ sessionID: string;
2177
+ requestID?: string;
2178
+ messageID: string;
2179
+ state: "accepted" | "running" | "completed" | "failed" | "cancelled" | "interrupted";
2180
+ acceptedAt: number;
2181
+ updatedAt: number;
2182
+ completedAt?: number;
2183
+ resultMessageID?: string;
2184
+ error?: {
2185
+ code: string;
2186
+ message: string;
2187
+ };
2188
+ };
2189
+ export type RuntimeDecisionResult = {
2190
+ sessionID: string;
2191
+ requestID: string;
2192
+ status: "resolved" | "indeterminate";
2193
+ decidedAt: number;
2194
+ };
2195
+ export type RuntimeDecisionInput = {
2196
+ sessionID: string;
2197
+ kind: "permission";
2198
+ requestID: string;
2199
+ reply: "once" | "session" | "project" | "always" | "reject";
2200
+ message?: string;
2201
+ } | {
2202
+ sessionID: string;
2203
+ kind: "question";
2204
+ requestID: string;
2205
+ answers: Array<QuestionAnswer>;
2206
+ } | {
2207
+ sessionID: string;
2208
+ kind: "question_reject";
2209
+ requestID: string;
2210
+ };
2211
+ export type RuntimeCapabilities = {
2212
+ protocolVersion: "1.0";
2213
+ serverVersion: string;
2214
+ idempotentPrompts: true;
2215
+ richInputs: true;
2216
+ runSnapshots: true;
2217
+ eventRetention: number;
2218
+ crashRecovery: "interrupt";
2219
+ decisionScope: "connected_runtime";
2220
+ };
2221
+ export type RuntimeSnapshot = {
2222
+ sessionID: string;
2223
+ runs: Array<RuntimeRun>;
2224
+ oldestSequence: number;
2225
+ latestSequence: number;
2226
+ permissions: Array<PermissionRequest>;
2227
+ questions: Array<QuestionRequest>;
2228
+ decisionScope: "connected_runtime";
2229
+ };
2147
2230
  export type RuntimeEvent = {
2148
2231
  sequence: number;
2149
2232
  sessionID: string;
@@ -8273,6 +8356,7 @@ export type SessionCreateData = {
8273
8356
  parentID?: string;
8274
8357
  title?: string;
8275
8358
  permission?: PermissionRuleset;
8359
+ workspace?: "isolated" | "project";
8276
8360
  };
8277
8361
  path?: never;
8278
8362
  query?: {
@@ -9726,7 +9810,26 @@ export type PermissionRespondResponse = PermissionRespondResponses[keyof Permiss
9726
9810
  export type RuntimePromptData = {
9727
9811
  body?: {
9728
9812
  sessionID: string;
9729
- message: string;
9813
+ messageID?: string;
9814
+ model?: {
9815
+ providerID: string;
9816
+ modelID: string;
9817
+ };
9818
+ variant?: string;
9819
+ tier?: string;
9820
+ context?: number;
9821
+ delegation?: boolean;
9822
+ delegationSettings?: {
9823
+ level?: "off" | "light" | "standard" | "high";
9824
+ workerModel?: {
9825
+ providerID: string;
9826
+ modelID: string;
9827
+ };
9828
+ autonomy?: "interactive" | "balanced" | "autonomous";
9829
+ };
9830
+ requestID?: string;
9831
+ message?: string;
9832
+ parts?: Array<TextPartInput | FilePartInput | AgentPartInput | ConversationPartInput | SubtaskPartInput>;
9730
9833
  effort: "normal" | "ultra";
9731
9834
  };
9732
9835
  path?: never;
@@ -9752,6 +9855,119 @@ export type RuntimePromptResponses = {
9752
9855
  202: RuntimePromptAccepted;
9753
9856
  };
9754
9857
  export type RuntimePromptResponse = RuntimePromptResponses[keyof RuntimePromptResponses];
9858
+ export type RuntimeCancelData = {
9859
+ body?: {
9860
+ sessionID: string;
9861
+ runID: string;
9862
+ };
9863
+ path?: never;
9864
+ query?: {
9865
+ directory?: string;
9866
+ };
9867
+ url: "/runtime/cancel";
9868
+ };
9869
+ export type RuntimeCancelErrors = {
9870
+ /**
9871
+ * Session or run not found
9872
+ */
9873
+ 404: unknown;
9874
+ };
9875
+ export type RuntimeCancelResponses = {
9876
+ /**
9877
+ * Current run state
9878
+ */
9879
+ 200: RuntimeRun;
9880
+ };
9881
+ export type RuntimeCancelResponse = RuntimeCancelResponses[keyof RuntimeCancelResponses];
9882
+ export type RuntimeDecideData = {
9883
+ body?: RuntimeDecisionInput;
9884
+ path?: never;
9885
+ query?: {
9886
+ directory?: string;
9887
+ };
9888
+ url: "/runtime/decision";
9889
+ };
9890
+ export type RuntimeDecideErrors = {
9891
+ /**
9892
+ * Invalid answer
9893
+ */
9894
+ 400: unknown;
9895
+ /**
9896
+ * Session not found
9897
+ */
9898
+ 404: unknown;
9899
+ /**
9900
+ * Conflicting or expired decision
9901
+ */
9902
+ 409: unknown;
9903
+ };
9904
+ export type RuntimeDecideResponses = {
9905
+ /**
9906
+ * Decision receipt
9907
+ */
9908
+ 200: RuntimeDecisionResult;
9909
+ };
9910
+ export type RuntimeDecideResponse = RuntimeDecideResponses[keyof RuntimeDecideResponses];
9911
+ export type RuntimeCapabilitiesData = {
9912
+ body?: never;
9913
+ path?: never;
9914
+ query?: {
9915
+ directory?: string;
9916
+ };
9917
+ url: "/runtime/capabilities";
9918
+ };
9919
+ export type RuntimeCapabilitiesResponses = {
9920
+ /**
9921
+ * Runtime capabilities
9922
+ */
9923
+ 200: RuntimeCapabilities;
9924
+ };
9925
+ export type RuntimeCapabilitiesResponse = RuntimeCapabilitiesResponses[keyof RuntimeCapabilitiesResponses];
9926
+ export type RuntimeGetRunData = {
9927
+ body?: never;
9928
+ path?: never;
9929
+ query: {
9930
+ directory?: string;
9931
+ sessionID: string;
9932
+ runID: string;
9933
+ };
9934
+ url: "/runtime/run";
9935
+ };
9936
+ export type RuntimeGetRunErrors = {
9937
+ /**
9938
+ * Session or run not found
9939
+ */
9940
+ 404: unknown;
9941
+ };
9942
+ export type RuntimeGetRunResponses = {
9943
+ /**
9944
+ * Research run
9945
+ */
9946
+ 200: RuntimeRun;
9947
+ };
9948
+ export type RuntimeGetRunResponse = RuntimeGetRunResponses[keyof RuntimeGetRunResponses];
9949
+ export type RuntimeSnapshotData = {
9950
+ body?: never;
9951
+ path?: never;
9952
+ query: {
9953
+ directory?: string;
9954
+ sessionID: string;
9955
+ };
9956
+ url: "/runtime/snapshot";
9957
+ };
9958
+ export type RuntimeSnapshotErrors = {
9959
+ /**
9960
+ * Session not found
9961
+ */
9962
+ 404: unknown;
9963
+ };
9964
+ export type RuntimeSnapshotResponses = {
9965
+ /**
9966
+ * Runtime snapshot
9967
+ */
9968
+ 200: RuntimeSnapshot;
9969
+ };
9970
+ export type RuntimeSnapshotResponse = RuntimeSnapshotResponses[keyof RuntimeSnapshotResponses];
9755
9971
  export type RuntimeReplayData = {
9756
9972
  body?: never;
9757
9973
  path?: never;
@@ -6,6 +6,7 @@ export declare function createOpenScience(options?: ServerOptions): Promise<{
6
6
  client: import("./client.js").OpenScienceClient;
7
7
  server: {
8
8
  url: string;
9
- close(): void;
9
+ pid: number;
10
+ close: () => Promise<void>;
10
11
  };
11
12
  }>;
@@ -3,11 +3,14 @@ export * from "./server.js";
3
3
  export * from "./runtime.js";
4
4
  import { createOpenScienceClient } from "./client.js";
5
5
  import { createOpenScienceServer } from "./server.js";
6
+ import { serverClientOptions } from "../server-process.js";
6
7
  export async function createOpenScience(options) {
8
+ const connection = serverClientOptions(options);
7
9
  const server = await createOpenScienceServer({
8
10
  ...options,
9
11
  });
10
12
  const client = createOpenScienceClient({
13
+ ...connection,
11
14
  baseUrl: server.url,
12
15
  });
13
16
  return {
@@ -1,5 +1,5 @@
1
1
  import { type OpenScienceClientConfig } from "./client.js";
2
- import type { RuntimeEvent, RuntimeEventReplay, RuntimePromptAccepted, RuntimePromptData } from "./gen/types.gen.js";
2
+ import type { RuntimeEvent, RuntimeEventReplay, RuntimePromptAccepted, RuntimePromptData, RuntimeCapabilities, RuntimeRun, RuntimeSnapshot, RuntimeDecisionInput, RuntimeDecisionResult } from "./gen/types.gen.js";
3
3
  export type RuntimePromptInput = NonNullable<RuntimePromptData["body"]>;
4
4
  export type RuntimeEventInput = {
5
5
  sessionID: string;
@@ -33,6 +33,27 @@ export declare class OpenScienceRuntime {
33
33
  #private;
34
34
  constructor(config?: OpenScienceRuntimeConfig);
35
35
  prompt(input: RuntimePromptInput): Promise<RuntimePromptAccepted>;
36
+ capabilities(): Promise<RuntimeCapabilities>;
37
+ getRun(input: {
38
+ sessionID: string;
39
+ runID: string;
40
+ }): Promise<RuntimeRun>;
41
+ snapshot(input: {
42
+ sessionID: string;
43
+ }): Promise<RuntimeSnapshot>;
44
+ cancel(input: {
45
+ sessionID: string;
46
+ runID: string;
47
+ }): Promise<RuntimeRun>;
48
+ decide(input: RuntimeDecisionInput): Promise<RuntimeDecisionResult>;
49
+ /** Snapshot reads survive event eviction. Waiting never submits new work or
50
+ * resolves a decision: callers can surface pending cards through snapshot. */
51
+ wait(input: {
52
+ sessionID: string;
53
+ runID: string;
54
+ signal?: AbortSignal;
55
+ intervalMs?: number;
56
+ }): Promise<RuntimeRun>;
36
57
  replay(input: Omit<RuntimeEventInput, "signal">): Promise<RuntimeEventReplay>;
37
58
  events(input: RuntimeEventInput): AsyncGenerator<RuntimeEvent, void, void>;
38
59
  }
@@ -49,6 +49,37 @@ export class OpenScienceRuntime {
49
49
  })
50
50
  .then((result) => result.data);
51
51
  }
52
+ capabilities() {
53
+ return this.#client.runtime.capabilities(undefined, { throwOnError: true }).then((result) => result.data);
54
+ }
55
+ getRun(input) {
56
+ return this.#client.runtime.getRun(input, { throwOnError: true }).then((result) => result.data);
57
+ }
58
+ snapshot(input) {
59
+ return this.#client.runtime.snapshot(input, { throwOnError: true }).then((result) => result.data);
60
+ }
61
+ cancel(input) {
62
+ return this.#client.runtime.cancel(input, { throwOnError: true }).then((result) => result.data);
63
+ }
64
+ decide(input) {
65
+ return this.#client.runtime
66
+ .decide({ runtimeDecisionInput: input }, { throwOnError: true })
67
+ .then((result) => result.data);
68
+ }
69
+ /** Snapshot reads survive event eviction. Waiting never submits new work or
70
+ * resolves a decision: callers can surface pending cards through snapshot. */
71
+ async wait(input) {
72
+ const interval = input.intervalMs ?? 1000;
73
+ if (!Number.isFinite(interval) || interval < 10)
74
+ throw new Error("Run polling interval must be at least 10 ms");
75
+ for (;;) {
76
+ input.signal?.throwIfAborted();
77
+ const result = await this.#client.runtime.getRun({ sessionID: input.sessionID, runID: input.runID }, { throwOnError: true, signal: input.signal });
78
+ if (result.data.state !== "accepted" && result.data.state !== "running")
79
+ return result.data;
80
+ await waitForReconnect(interval, input.signal);
81
+ }
82
+ }
52
83
  replay(input) {
53
84
  return this.#client.runtime
54
85
  .replay(input, {
@@ -75,6 +106,12 @@ export class OpenScienceRuntime {
75
106
  },
76
107
  });
77
108
  for await (const event of result.stream) {
109
+ if (event.sessionID !== input.sessionID || !Number.isSafeInteger(event.sequence) || event.sequence < 1)
110
+ throw new RuntimeEventCursorError("The runtime returned an invalid session or sequence");
111
+ if (lastSequence !== undefined && event.sequence <= lastSequence)
112
+ continue;
113
+ if (lastSequence !== undefined && event.sequence !== lastSequence + 1)
114
+ throw new RuntimeEventCursorError("The runtime event stream has a gap; refresh the session snapshot");
78
115
  lastSequence = event.sequence;
79
116
  failures = 0;
80
117
  delivered = true;
@@ -1,12 +1,10 @@
1
- import { type Config } from "./gen/types.gen.js";
2
- export type ServerOptions = {
3
- hostname?: string;
4
- port?: number;
5
- signal?: AbortSignal;
6
- timeout?: number;
1
+ import type { Config } from "./gen/types.gen.js";
2
+ import { type ServerProcessOptions } from "../server-process.js";
3
+ export type ServerOptions = ServerProcessOptions & {
7
4
  config?: Config;
8
5
  };
9
6
  export declare function createOpenScienceServer(options?: ServerOptions): Promise<{
10
7
  url: string;
11
- close(): void;
8
+ pid: number;
9
+ close: () => Promise<void>;
12
10
  }>;
@@ -1,68 +1,4 @@
1
- import { spawn } from "node:child_process";
2
- export async function createOpenScienceServer(options) {
3
- options = Object.assign({
4
- hostname: "127.0.0.1",
5
- port: 4096,
6
- timeout: 5000,
7
- }, options ?? {});
8
- const args = [`serve`, `--port=${options.port}`];
9
- if (options.config?.logLevel)
10
- args.push(`--log-level=${options.config.logLevel}`);
11
- const proc = spawn(`openscience`, args, {
12
- signal: options.signal,
13
- env: {
14
- ...process.env,
15
- OPENSCIENCE_CONFIG_CONTENT: JSON.stringify(options.config ?? {}),
16
- },
17
- });
18
- const url = await new Promise((resolve, reject) => {
19
- const id = setTimeout(() => {
20
- reject(new Error(`Timeout waiting for server to start after ${options.timeout}ms`));
21
- }, options.timeout);
22
- let output = "";
23
- proc.stdout?.on("data", (chunk) => {
24
- output += chunk.toString();
25
- const lines = output.split("\n");
26
- for (const line of lines) {
27
- if (line.startsWith("openscience server listening")) {
28
- const match = line.match(/on\s+(https?:\/\/[^\s]+)/);
29
- if (!match) {
30
- clearTimeout(id);
31
- reject(new Error(`Failed to parse server url from output: ${line}`));
32
- return;
33
- }
34
- clearTimeout(id);
35
- resolve(match[1]);
36
- return;
37
- }
38
- }
39
- });
40
- proc.stderr?.on("data", (chunk) => {
41
- output += chunk.toString();
42
- });
43
- proc.on("exit", (code) => {
44
- clearTimeout(id);
45
- let msg = `Server exited with code ${code}`;
46
- if (output.trim()) {
47
- msg += `\nServer output: ${output}`;
48
- }
49
- reject(new Error(msg));
50
- });
51
- proc.on("error", (error) => {
52
- clearTimeout(id);
53
- reject(error);
54
- });
55
- if (options.signal) {
56
- options.signal.addEventListener("abort", () => {
57
- clearTimeout(id);
58
- reject(new Error("Aborted"));
59
- });
60
- }
61
- });
62
- return {
63
- url,
64
- close() {
65
- proc.kill();
66
- },
67
- };
1
+ import { startServer } from "../server-process.js";
2
+ export function createOpenScienceServer(options) {
3
+ return startServer(options);
68
4
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@synsci/sdk",
4
- "version": "2.0.77",
4
+ "version": "2.0.78-test.34098503148",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
7
7
  "scripts": {
@@ -1 +0,0 @@
1
- export {};