@crazx/dsh-api-session-controller 0.1.2-alpha.3.zw.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.
Files changed (74) hide show
  1. package/LICENSE +21 -0
  2. package/README.i18n.yaml +6 -0
  3. package/README.md +74 -0
  4. package/README.zh.md +74 -0
  5. package/lib/client.js +2724 -0
  6. package/lib/index.js +2826 -0
  7. package/lib/invariant.js +13 -0
  8. package/lib/typert.host.d.ts +3 -0
  9. package/lib/typert.host.js +2574 -0
  10. package/lib/typert.remote-client.d.ts +67 -0
  11. package/lib/typert.remote-client.js +1119 -0
  12. package/lib/types/agent.d.ts +156 -0
  13. package/lib/types/agent.js +537 -0
  14. package/lib/types/catalog.d.ts +11 -0
  15. package/lib/types/catalog.js +58 -0
  16. package/lib/types/client/contract/events.d.ts +71 -0
  17. package/lib/types/client/contract/events.js +91 -0
  18. package/lib/types/client/contract/session.d.ts +150 -0
  19. package/lib/types/client/contract/session.js +2 -0
  20. package/lib/types/client/contract/sessions.d.ts +125 -0
  21. package/lib/types/client/contract/sessions.js +2 -0
  22. package/lib/types/client/contract/snapshot.d.ts +82 -0
  23. package/lib/types/client/contract/snapshot.js +2 -0
  24. package/lib/types/client/index.d.ts +30 -0
  25. package/lib/types/client/index.js +48 -0
  26. package/lib/types/client/ordered-baseline.d.ts +12 -0
  27. package/lib/types/client/ordered-baseline.js +41 -0
  28. package/lib/types/client/scope.d.ts +36 -0
  29. package/lib/types/client/scope.js +54 -0
  30. package/lib/types/client/sessions/history-records.d.ts +22 -0
  31. package/lib/types/client/sessions/history-records.js +31 -0
  32. package/lib/types/client/sessions/lineage.d.ts +38 -0
  33. package/lib/types/client/sessions/lineage.js +56 -0
  34. package/lib/types/client/sessions/manager.d.ts +280 -0
  35. package/lib/types/client/sessions/manager.js +894 -0
  36. package/lib/types/client/sessions/notifier.d.ts +39 -0
  37. package/lib/types/client/sessions/notifier.js +98 -0
  38. package/lib/types/client/sessions/projection-store.d.ts +108 -0
  39. package/lib/types/client/sessions/projection-store.js +129 -0
  40. package/lib/types/client/sessions/queue-mirror.d.ts +26 -0
  41. package/lib/types/client/sessions/queue-mirror.js +61 -0
  42. package/lib/types/client/sessions/remotes.d.ts +30 -0
  43. package/lib/types/client/sessions/remotes.js +8 -0
  44. package/lib/types/client/sessions/service.d.ts +349 -0
  45. package/lib/types/client/sessions/service.js +574 -0
  46. package/lib/types/client/sessions/session.d.ts +294 -0
  47. package/lib/types/client/sessions/session.js +711 -0
  48. package/lib/types/client/time-zone.d.ts +8 -0
  49. package/lib/types/client/time-zone.js +14 -0
  50. package/lib/types/client/transport.d.ts +73 -0
  51. package/lib/types/client/transport.js +106 -0
  52. package/lib/types/commands.d.ts +69 -0
  53. package/lib/types/commands.js +544 -0
  54. package/lib/types/control.d.ts +23 -0
  55. package/lib/types/control.js +192 -0
  56. package/lib/types/file-references.d.ts +27 -0
  57. package/lib/types/file-references.js +69 -0
  58. package/lib/types/history.d.ts +31 -0
  59. package/lib/types/history.js +376 -0
  60. package/lib/types/index.d.ts +171 -0
  61. package/lib/types/index.js +424 -0
  62. package/lib/types/invariant.d.ts +9 -0
  63. package/lib/types/invariant.js +12 -0
  64. package/lib/types/list.d.ts +53 -0
  65. package/lib/types/list.js +405 -0
  66. package/lib/types/model-selection-projection.d.ts +8 -0
  67. package/lib/types/model-selection-projection.js +66 -0
  68. package/lib/types/remote-events.d.ts +8 -0
  69. package/lib/types/remote-events.js +2 -0
  70. package/lib/types/skill-catalog.d.ts +28 -0
  71. package/lib/types/skill-catalog.js +192 -0
  72. package/lib/types/types.d.ts +505 -0
  73. package/lib/types/types.js +6 -0
  74. package/package.json +154 -0
@@ -0,0 +1,8 @@
1
+ /** Browser-owned time-zone sampling for prompt RPC provenance. */
2
+ /**
3
+ * Resolve the current browser IANA zone for one outbound operation.
4
+ * @returns The browser-provided canonical zone.
5
+ * @throws when the runtime cannot provide a non-empty zone.
6
+ */
7
+ export declare function resolvedClientTimeZone(): string;
8
+ //# sourceMappingURL=time-zone.d.ts.map
@@ -0,0 +1,14 @@
1
+ /** Browser-owned time-zone sampling for prompt RPC provenance. */
2
+ /**
3
+ * Resolve the current browser IANA zone for one outbound operation.
4
+ * @returns The browser-provided canonical zone.
5
+ * @throws when the runtime cannot provide a non-empty zone.
6
+ */
7
+ export function resolvedClientTimeZone() {
8
+ const timeZone = new Intl.DateTimeFormat().resolvedOptions().timeZone;
9
+ if (typeof timeZone !== 'string' || timeZone.length === 0) {
10
+ throw new Error('browser time zone is unavailable');
11
+ }
12
+ return timeZone;
13
+ }
14
+ //# sourceMappingURL=time-zone.js.map
@@ -0,0 +1,73 @@
1
+ /** Session-specific adapters for Gateway-owned Remote stream lifecycles. */
2
+ import { RemoteJournalStream, RemoteSnapshotStream, RemoteStreamCarrierError, type ClientRemote, type RemoteJournalFrame } from '@deepseek-ai/dsh-api-gateway/client';
3
+ import type { SessionAddress, SessionControlFrame, SessionHistoryRecord, SessionPage, SessionPageRequest, SessionProjectionBaseline } from '../types.ts';
4
+ import type { SessionEventLikeEntry, SessionLiveEventEntry } from './contract/events.ts';
5
+ import type { SessionRemotes } from './sessions/remotes.ts';
6
+ export { SESSION_SEARCH_RESULT_LIMIT, SESSION_SEARCH_SNIPPET_MAX_CODE_POINTS, } from '../types.ts';
7
+ /** Pagination fields bound to an already-addressed Session journal. */
8
+ export type ClientSessionPageRequest = Omit<SessionPageRequest, 'address' | 'throughSeq'>;
9
+ /** Complete generated `ctx.remote.session` namespace. */
10
+ export type SessionRemote = ClientRemote['session'];
11
+ /** Opening metadata carried only by a follow snapshot, never by loadOlder pages. */
12
+ interface SessionJournalPage extends SessionPage {
13
+ readonly projections?: SessionProjectionBaseline;
14
+ }
15
+ /** One complete publication from the Session journal stream. */
16
+ export type SessionJournalChange = {
17
+ readonly type: 'replace' | 'prepend';
18
+ readonly page: SessionJournalPage;
19
+ readonly entries: readonly SessionEventLikeEntry[];
20
+ readonly hasMore: boolean;
21
+ } | {
22
+ readonly type: 'append';
23
+ readonly entry: SessionLiveEventEntry;
24
+ };
25
+ type SessionControlBaselineFrame = Extract<SessionControlFrame, {
26
+ type: 'baseline';
27
+ }>;
28
+ type SessionControlDeltaFrame = Exclude<SessionControlFrame, SessionControlBaselineFrame>;
29
+ /** Gateway-owned control snapshot stream configured for Session frames. */
30
+ export type SessionControlStream = RemoteSnapshotStream<SessionControlBaselineFrame, SessionControlDeltaFrame>;
31
+ /** Domain sinks used by the Host-wide Session control stream. */
32
+ export interface SessionControlStreamOptions {
33
+ /** Apply a complete baseline or one later update. */
34
+ readonly accept: (frame: SessionControlFrame) => void;
35
+ /** Observe a retryable carrier loss before reconnection. */
36
+ readonly carrierFailed?: (error: RemoteStreamCarrierError) => void;
37
+ /** Publish a terminal business or protocol failure. */
38
+ readonly failed: (error: unknown) => void;
39
+ }
40
+ /** Domain sinks used by one addressed Session event journal. */
41
+ export interface SessionEventStreamOptions {
42
+ /** Apply one complete event-window change. */
43
+ readonly publish: (change: SessionJournalChange) => void;
44
+ /** Observe a retryable carrier loss before reconnection. */
45
+ readonly carrierFailed?: (error: RemoteStreamCarrierError) => void;
46
+ /** Publish a terminal stream, page, or protocol failure after opening. */
47
+ readonly failed: (error: unknown) => void;
48
+ }
49
+ /**
50
+ * Create the Host-wide Session control snapshot stream.
51
+ * @param remote - generated Session namespace and Gateway stream factory.
52
+ * @param options - Session state destinations.
53
+ * @returns an unstarted stream owned by the Client Session runtime.
54
+ */
55
+ export declare function createSessionControlStream(remote: SessionRemotes, options: SessionControlStreamOptions): SessionControlStream;
56
+ /** Gateway-owned event journal bound to one ordinary or direct-subagent Session address. */
57
+ export declare class SessionEventStream extends RemoteJournalStream<SessionJournalPage, SessionHistoryRecord, number, ClientSessionPageRequest> {
58
+ private readonly remote;
59
+ private readonly address;
60
+ /**
61
+ * @param remote - generated Session namespace and Gateway stream factory.
62
+ * @param address - durable ordinary-Session or direct-subagent address.
63
+ * @param options - Session event-window destinations.
64
+ */
65
+ constructor(remote: SessionRemotes, address: SessionAddress, options: SessionEventStreamOptions);
66
+ /** @inheritdoc */
67
+ protected follow(request: ClientSessionPageRequest, signal: AbortSignal): AsyncIterable<RemoteJournalFrame<SessionHistoryRecord, number, SessionJournalPage>>;
68
+ /** @inheritdoc */
69
+ protected readPage(request: ClientSessionPageRequest, throughSeq: number, signal: AbortSignal): Promise<SessionJournalPage>;
70
+ /** @inheritdoc */
71
+ protected repairRequest(request: ClientSessionPageRequest): ClientSessionPageRequest;
72
+ }
73
+ //# sourceMappingURL=transport.d.ts.map
@@ -0,0 +1,106 @@
1
+ /** Session-specific adapters for Gateway-owned Remote stream lifecycles. */
2
+ import { RemoteError } from '@deepseek-ai/dsh-typert-protocol';
3
+ import { RemoteJournalStream, RemoteSnapshotStream, RemoteStreamCarrierError, } from '@deepseek-ai/dsh-api-gateway/client';
4
+ import { historyEntries, historyRecordFirstSeq, historyRecordLastSeq, } from "./sessions/history-records.js";
5
+ export { SESSION_SEARCH_RESULT_LIMIT, SESSION_SEARCH_SNIPPET_MAX_CODE_POINTS, } from "../types.js";
6
+ function toSessionJournalChange(change) {
7
+ switch (change.type) {
8
+ case 'replace':
9
+ case 'prepend':
10
+ return { ...change, entries: historyEntries(change.entries) };
11
+ case 'append': {
12
+ if (change.entry.type !== 'event') {
13
+ throw new RemoteError('gateway/internal', 'session live stream emitted a packed history record', {});
14
+ }
15
+ return {
16
+ type: 'append',
17
+ entry: change.entry,
18
+ };
19
+ }
20
+ }
21
+ }
22
+ /**
23
+ * Create the Host-wide Session control snapshot stream.
24
+ * @param remote - generated Session namespace and Gateway stream factory.
25
+ * @param options - Session state destinations.
26
+ * @returns an unstarted stream owned by the Client Session runtime.
27
+ */
28
+ export function createSessionControlStream(remote, options) {
29
+ const stream = remote.$stream({
30
+ name: 'session control stream',
31
+ open: signal => remote.session.control(signal),
32
+ ended: accepted => accepted
33
+ ? new RemoteStreamCarrierError('session control stream ended without a terminal result')
34
+ : new Error('session control stream ended before its opening snapshot'),
35
+ ...(options.carrierFailed === undefined ? {} : { carrierFailed: options.carrierFailed }),
36
+ });
37
+ return new RemoteSnapshotStream(stream, {
38
+ name: 'session control stream',
39
+ isSnapshot: (frame) => frame.type === 'baseline',
40
+ replace: options.accept,
41
+ update: options.accept,
42
+ failed: options.failed,
43
+ });
44
+ }
45
+ /** Gateway-owned event journal bound to one ordinary or direct-subagent Session address. */
46
+ export class SessionEventStream extends RemoteJournalStream {
47
+ remote;
48
+ address;
49
+ /**
50
+ * @param remote - generated Session namespace and Gateway stream factory.
51
+ * @param address - durable ordinary-Session or direct-subagent address.
52
+ * @param options - Session event-window destinations.
53
+ */
54
+ constructor(remote, address, options) {
55
+ super(remote, {
56
+ name: 'session event stream',
57
+ emptyCursor: -1,
58
+ entries: page => page.records,
59
+ hasMore: page => page.hasMore,
60
+ first: historyRecordFirstSeq,
61
+ last: historyRecordLastSeq,
62
+ compare: (left, right) => left - right,
63
+ follows: (left, right) => right === left + 1,
64
+ publish: (change) => { options.publish(toSessionJournalChange(change)); },
65
+ ...(options.carrierFailed === undefined
66
+ ? {}
67
+ : { carrierFailed: options.carrierFailed }),
68
+ failed: options.failed,
69
+ });
70
+ this.remote = remote;
71
+ this.address = address;
72
+ }
73
+ /** @inheritdoc */
74
+ async *follow(request, signal) {
75
+ for await (const frame of this.remote.session.follow({
76
+ address: this.address,
77
+ ...(request.maxMessages === undefined ? {} : { maxMessages: request.maxMessages }),
78
+ }, signal)) {
79
+ if (frame.type === 'snapshot') {
80
+ yield {
81
+ type: 'opened',
82
+ cursor: frame.cursor,
83
+ page: {
84
+ records: frame.records,
85
+ hasMore: frame.hasMore,
86
+ projections: frame.projections,
87
+ },
88
+ };
89
+ continue;
90
+ }
91
+ yield { type: 'entry', entry: frame };
92
+ }
93
+ }
94
+ /** @inheritdoc */
95
+ async readPage(request, throughSeq, signal) {
96
+ const result = await this.remote.session.page({ address: this.address, throughSeq, ...request }, signal);
97
+ if (!result.ok)
98
+ throw result.error;
99
+ return result.value;
100
+ }
101
+ /** @inheritdoc */
102
+ repairRequest(request) {
103
+ return request.maxMessages === undefined ? {} : { maxMessages: request.maxMessages };
104
+ }
105
+ }
106
+ //# sourceMappingURL=transport.js.map
@@ -0,0 +1,69 @@
1
+ /** Session commands whose activation policy is explicit at each Remote method. */
2
+ import type { Context } from '@deepseek-ai/cordis';
3
+ import { ApiSessionAgentController } from './agent.ts';
4
+ import type { SessionAttachmentRequest, SessionAttachmentValue, SessionCancelRequest, SessionCancelValue, SessionCreateRequest, SessionCreateValue, SessionForkRequest, SessionForkValue, SessionPromptRequest, SessionPromptValue, SessionRenameRequest, SessionRenameValue, SessionSelectModelRequest, SessionSelectModelValue, SessionUpdateQueueRequest, SessionUpdateQueueValue } from './types.ts';
5
+ /** Implements Session business commands delegated by the Session Controller Remote service. */
6
+ export declare class SessionCommandController {
7
+ private readonly ctx;
8
+ private readonly agents;
9
+ private readonly defaultCwd;
10
+ /**
11
+ * @param ctx - Host context carrying Agent, model, attachment, title, and Workspace services.
12
+ * @param agents - sole owner of create, resume, and Session-local model selection.
13
+ * @param defaultCwd - project directory used when create names neither a Workspace nor a cwd.
14
+ */
15
+ constructor(ctx: Context, agents: ApiSessionAgentController, defaultCwd: string);
16
+ /**
17
+ * Create or idempotently adopt one ordinary Session.
18
+ * @param request - requested identity, location, and Agent preset.
19
+ * @returns the Session identity and resolved preset when configured.
20
+ */
21
+ create(request: SessionCreateRequest): Promise<SessionCreateValue>;
22
+ /**
23
+ * Validate and install one Session-local model selection.
24
+ * @param request - Session identity and requested model selection.
25
+ * @returns the normalized selection installed for the Session.
26
+ */
27
+ selectModel(request: SessionSelectModelRequest): Promise<SessionSelectModelValue>;
28
+ /**
29
+ * Normalize and append a user-owned Session title.
30
+ * @param request - Session identity and proposed title.
31
+ * @returns the accepted title and durable event sequence.
32
+ */
33
+ rename(request: SessionRenameRequest): Promise<SessionRenameValue>;
34
+ /**
35
+ * Create a new ordinary Session from one completed-turn prefix.
36
+ * @param request - source Session and optional event anchor.
37
+ * @returns the new Session identity.
38
+ */
39
+ fork(request: SessionForkRequest): Promise<SessionForkValue>;
40
+ /**
41
+ * Admit one browser prompt after explicit Agent resume and image validation.
42
+ * @param request - Session identity, prompt content, source metadata, and delivery mode.
43
+ * @returns acknowledgement that the Agent accepted the prompt.
44
+ */
45
+ prompt(request: SessionPromptRequest): Promise<SessionPromptValue>;
46
+ /**
47
+ * Read one durable image after proving the Session log references it.
48
+ * @param request - Session and attachment identities used for authorization.
49
+ * @returns the durable attachment reference and base64-encoded bytes.
50
+ */
51
+ attachment(request: SessionAttachmentRequest): Promise<SessionAttachmentValue>;
52
+ /**
53
+ * Mutate one still-pending queue occurrence without resuming a cold Agent.
54
+ * @param request - Session, queue item, and requested mutation.
55
+ * @returns acknowledgement that the queue mutation was applied.
56
+ */
57
+ updateQueue(request: SessionUpdateQueueRequest): SessionUpdateQueueValue;
58
+ /**
59
+ * Cancel one live ordinary Agent while retaining pending inbox work.
60
+ * @param request - Session whose active Agent turn is cancelled.
61
+ * @returns acknowledgement that cancellation was requested.
62
+ */
63
+ cancel(request: SessionCancelRequest): SessionCancelValue;
64
+ private resolveAgent;
65
+ private rejectCreation;
66
+ private readSessionState;
67
+ private forkWorkspace;
68
+ }
69
+ //# sourceMappingURL=commands.d.ts.map