@forthix/forthic 0.7.0 → 0.7.2

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 (95) hide show
  1. package/dist/cjs/common/type_utils.js.map +1 -1
  2. package/dist/cjs/forthic/interpreter.d.ts +2 -1
  3. package/dist/cjs/forthic/interpreter.js +10 -0
  4. package/dist/cjs/forthic/interpreter.js.map +1 -1
  5. package/dist/cjs/forthic/literals.d.ts +0 -1
  6. package/dist/cjs/forthic/literals.js +14 -15
  7. package/dist/cjs/forthic/literals.js.map +1 -1
  8. package/dist/cjs/forthic/modules/standard/datetime_module.d.ts +0 -1
  9. package/dist/cjs/forthic/modules/standard/datetime_module.js +19 -20
  10. package/dist/cjs/forthic/modules/standard/datetime_module.js.map +1 -1
  11. package/dist/cjs/forthic/utils.d.ts +0 -1
  12. package/dist/cjs/forthic/utils.js +1 -2
  13. package/dist/cjs/forthic/utils.js.map +1 -1
  14. package/dist/cjs/grpc/serializer.js +3 -4
  15. package/dist/cjs/grpc/serializer.js.map +1 -1
  16. package/dist/cjs/grpc/server.test.d.ts +1 -0
  17. package/dist/cjs/grpc/server.test.js +156 -0
  18. package/dist/cjs/grpc/server.test.js.map +1 -0
  19. package/dist/cjs/grpc/temporal_utils.d.ts +36 -0
  20. package/dist/cjs/grpc/temporal_utils.js +80 -0
  21. package/dist/cjs/grpc/temporal_utils.js.map +1 -0
  22. package/dist/cjs/test-setup.d.ts +1 -0
  23. package/dist/cjs/test-setup.js +4 -0
  24. package/dist/cjs/test-setup.js.map +1 -0
  25. package/dist/cjs/websocket/action_cable_client.d.ts +106 -0
  26. package/dist/cjs/websocket/action_cable_client.js +269 -0
  27. package/dist/cjs/websocket/action_cable_client.js.map +1 -0
  28. package/dist/cjs/websocket/client.d.ts +103 -0
  29. package/dist/cjs/websocket/client.js +266 -0
  30. package/dist/cjs/websocket/client.js.map +1 -0
  31. package/dist/cjs/websocket/remote_module.d.ts +68 -0
  32. package/dist/cjs/websocket/remote_module.js +107 -0
  33. package/dist/cjs/websocket/remote_module.js.map +1 -0
  34. package/dist/cjs/websocket/remote_word.d.ts +53 -0
  35. package/dist/cjs/websocket/remote_word.js +93 -0
  36. package/dist/cjs/websocket/remote_word.js.map +1 -0
  37. package/dist/cjs/websocket/runtime_manager.d.ts +69 -0
  38. package/dist/cjs/websocket/runtime_manager.js +112 -0
  39. package/dist/cjs/websocket/runtime_manager.js.map +1 -0
  40. package/dist/cjs/websocket/serializer.js +3 -4
  41. package/dist/cjs/websocket/serializer.js.map +1 -1
  42. package/dist/esm/common/type_utils.js.map +1 -1
  43. package/dist/esm/forthic/interpreter.d.ts +2 -1
  44. package/dist/esm/forthic/interpreter.js +11 -1
  45. package/dist/esm/forthic/interpreter.js.map +1 -1
  46. package/dist/esm/forthic/literals.d.ts +0 -1
  47. package/dist/esm/forthic/literals.js +0 -1
  48. package/dist/esm/forthic/literals.js.map +1 -1
  49. package/dist/esm/forthic/modules/standard/datetime_module.d.ts +0 -1
  50. package/dist/esm/forthic/modules/standard/datetime_module.js +0 -1
  51. package/dist/esm/forthic/modules/standard/datetime_module.js.map +1 -1
  52. package/dist/esm/forthic/utils.d.ts +0 -1
  53. package/dist/esm/forthic/utils.js +0 -1
  54. package/dist/esm/forthic/utils.js.map +1 -1
  55. package/dist/esm/grpc/serializer.js +0 -1
  56. package/dist/esm/grpc/serializer.js.map +1 -1
  57. package/dist/esm/grpc/server.test.d.ts +1 -0
  58. package/dist/esm/grpc/server.test.js +121 -0
  59. package/dist/esm/grpc/server.test.js.map +1 -0
  60. package/dist/esm/grpc/temporal_utils.d.ts +36 -0
  61. package/dist/esm/grpc/temporal_utils.js +72 -0
  62. package/dist/esm/grpc/temporal_utils.js.map +1 -0
  63. package/dist/esm/test-setup.d.ts +1 -0
  64. package/dist/esm/test-setup.js +2 -0
  65. package/dist/esm/test-setup.js.map +1 -0
  66. package/dist/esm/websocket/action_cable_client.d.ts +106 -0
  67. package/dist/esm/websocket/action_cable_client.js +265 -0
  68. package/dist/esm/websocket/action_cable_client.js.map +1 -0
  69. package/dist/esm/websocket/client.d.ts +103 -0
  70. package/dist/esm/websocket/client.js +262 -0
  71. package/dist/esm/websocket/client.js.map +1 -0
  72. package/dist/esm/websocket/remote_module.d.ts +68 -0
  73. package/dist/esm/websocket/remote_module.js +103 -0
  74. package/dist/esm/websocket/remote_module.js.map +1 -0
  75. package/dist/esm/websocket/remote_word.d.ts +53 -0
  76. package/dist/esm/websocket/remote_word.js +89 -0
  77. package/dist/esm/websocket/remote_word.js.map +1 -0
  78. package/dist/esm/websocket/runtime_manager.d.ts +69 -0
  79. package/dist/esm/websocket/runtime_manager.js +108 -0
  80. package/dist/esm/websocket/runtime_manager.js.map +1 -0
  81. package/dist/esm/websocket/serializer.js +0 -1
  82. package/dist/esm/websocket/serializer.js.map +1 -1
  83. package/package.json +3 -2
  84. package/dist/cjs/forthic/decorators/schemaUtils.d.ts +0 -70
  85. package/dist/cjs/forthic/decorators/schemaUtils.js +0 -77
  86. package/dist/cjs/forthic/decorators/schemaUtils.js.map +0 -1
  87. package/dist/cjs/forthic/decorators/stackEffect.d.ts +0 -63
  88. package/dist/cjs/forthic/decorators/stackEffect.js +0 -179
  89. package/dist/cjs/forthic/decorators/stackEffect.js.map +0 -1
  90. package/dist/esm/forthic/decorators/schemaUtils.d.ts +0 -70
  91. package/dist/esm/forthic/decorators/schemaUtils.js +0 -72
  92. package/dist/esm/forthic/decorators/schemaUtils.js.map +0 -1
  93. package/dist/esm/forthic/decorators/stackEffect.d.ts +0 -63
  94. package/dist/esm/forthic/decorators/stackEffect.js +0 -174
  95. package/dist/esm/forthic/decorators/stackEffect.js.map +0 -1
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ /**
37
+ * Phase 11.1: Basic server tests
38
+ * Verify that the TypeScript gRPC server can start and listen on port 50052
39
+ */
40
+ const server_1 = require("./server");
41
+ const grpc = __importStar(require("@grpc/grpc-js"));
42
+ const protoLoader = __importStar(require("@grpc/proto-loader"));
43
+ const path = __importStar(require("path"));
44
+ describe('TypeScript gRPC Server', () => {
45
+ let server = null;
46
+ const TEST_PORT = 50053; // Use different port to avoid conflicts
47
+ afterEach(async () => {
48
+ // Clean up server if running
49
+ if (server) {
50
+ await new Promise((resolve) => {
51
+ server.tryShutdown(() => {
52
+ resolve();
53
+ });
54
+ });
55
+ server = null;
56
+ }
57
+ });
58
+ test('server starts and listens on specified port', async () => {
59
+ // Start server in background (don't await)
60
+ const serverPromise = (0, server_1.serve)(TEST_PORT);
61
+ // Give server time to start
62
+ await new Promise((resolve) => setTimeout(resolve, 1000));
63
+ // Try to connect with a client
64
+ const possiblePaths = [
65
+ path.join(__dirname, '../../../../forthic/protos/forthic_runtime.proto'),
66
+ path.join(__dirname, '../../../forthic/protos/forthic_runtime.proto'),
67
+ path.join(process.cwd(), '../forthic/protos/forthic_runtime.proto'),
68
+ ];
69
+ let PROTO_PATH = possiblePaths[0];
70
+ const fs = require('fs');
71
+ for (const tryPath of possiblePaths) {
72
+ if (fs.existsSync(tryPath)) {
73
+ PROTO_PATH = tryPath;
74
+ break;
75
+ }
76
+ }
77
+ const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
78
+ keepCase: true,
79
+ longs: Number,
80
+ enums: String,
81
+ defaults: true,
82
+ oneofs: true,
83
+ });
84
+ const protoDescriptor = grpc.loadPackageDefinition(packageDefinition);
85
+ const forthicProto = protoDescriptor.forthic;
86
+ // Create client
87
+ const client = new forthicProto.ForthicRuntime(`localhost:${TEST_PORT}`, grpc.credentials.createInsecure());
88
+ // Test that we can connect by calling ListModules
89
+ const response = await new Promise((resolve, reject) => {
90
+ client.ListModules({}, (error, response) => {
91
+ if (error) {
92
+ reject(error);
93
+ }
94
+ else {
95
+ resolve(response);
96
+ }
97
+ });
98
+ });
99
+ // Should succeed with empty module list (no TS-specific modules yet)
100
+ expect(response).toBeDefined();
101
+ expect(response.modules).toBeDefined();
102
+ expect(Array.isArray(response.modules)).toBe(true);
103
+ // Clean up client
104
+ grpc.closeClient(client);
105
+ }, 10000); // 10 second timeout
106
+ test('server can execute simple stdlib word', async () => {
107
+ // Start server
108
+ const serverPromise = (0, server_1.serve)(TEST_PORT);
109
+ await new Promise((resolve) => setTimeout(resolve, 1000));
110
+ // Load proto
111
+ const possiblePaths = [
112
+ path.join(__dirname, '../../../../forthic/protos/forthic_runtime.proto'),
113
+ path.join(__dirname, '../../../forthic/protos/forthic_runtime.proto'),
114
+ path.join(process.cwd(), '../forthic/protos/forthic_runtime.proto'),
115
+ ];
116
+ let PROTO_PATH = possiblePaths[0];
117
+ const fs = require('fs');
118
+ for (const tryPath of possiblePaths) {
119
+ if (fs.existsSync(tryPath)) {
120
+ PROTO_PATH = tryPath;
121
+ break;
122
+ }
123
+ }
124
+ const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
125
+ keepCase: true,
126
+ longs: Number,
127
+ enums: String,
128
+ defaults: true,
129
+ oneofs: true,
130
+ });
131
+ const protoDescriptor = grpc.loadPackageDefinition(packageDefinition);
132
+ const forthicProto = protoDescriptor.forthic;
133
+ const client = new forthicProto.ForthicRuntime(`localhost:${TEST_PORT}`, grpc.credentials.createInsecure());
134
+ // Execute DUP word (duplicates top stack item)
135
+ const response = await new Promise((resolve, reject) => {
136
+ client.ExecuteWord({
137
+ word_name: 'DUP',
138
+ stack: [{ int_value: 42 }],
139
+ }, (error, response) => {
140
+ if (error) {
141
+ reject(error);
142
+ }
143
+ else {
144
+ resolve(response);
145
+ }
146
+ });
147
+ });
148
+ // Should have [42, 42] on stack
149
+ expect(response.result_stack).toBeDefined();
150
+ expect(response.result_stack.length).toBe(2);
151
+ expect(response.result_stack[0].int_value).toBe(42);
152
+ expect(response.result_stack[1].int_value).toBe(42);
153
+ grpc.closeClient(client);
154
+ }, 10000);
155
+ });
156
+ //# sourceMappingURL=server.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.test.js","sourceRoot":"","sources":["../../../src/grpc/server.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;GAGG;AACH,qCAAiC;AACjC,oDAAsC;AACtC,gEAAkD;AAClD,2CAA6B;AAE7B,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,IAAI,MAAM,GAAuB,IAAI,CAAC;IACtC,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,wCAAwC;IAEjE,SAAS,CAAC,KAAK,IAAI,EAAE;QACnB,6BAA6B;QAC7B,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAA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BAChB,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,QAAQ,CAAC,CAAC;gBACpB,CAAC;YACH,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,gCAAgC;QAChC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,WAAW,EAAE,CAAC;QAC5C,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC7C,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACpD,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAEpD,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAC3B,CAAC,EAAE,KAAK,CAAC,CAAC;AACZ,CAAC,CAAC,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Temporal Type Utilities
3
+ *
4
+ * Provides duck-typing helpers for checking Temporal types.
5
+ * Uses duck typing instead of instanceof to avoid issues with multiple
6
+ * instances of temporal-polyfill being loaded.
7
+ */
8
+ /**
9
+ * Check if a value is a Temporal.PlainDate
10
+ * PlainDate has year, month, day properties but no hour property
11
+ */
12
+ export declare function isPlainDate(value: any): boolean;
13
+ /**
14
+ * Check if a value is a Temporal.Instant
15
+ * Instant has epochNanoseconds property as a bigint
16
+ */
17
+ export declare function isInstant(value: any): boolean;
18
+ /**
19
+ * Check if a value is a Temporal.ZonedDateTime
20
+ * ZonedDateTime has a timeZoneId property
21
+ */
22
+ export declare function isZonedDateTime(value: any): boolean;
23
+ /**
24
+ * Check if a value is a Temporal.PlainTime
25
+ * PlainTime has hour and minute properties but no year
26
+ */
27
+ export declare function isPlainTime(value: any): boolean;
28
+ /**
29
+ * Check if a value is a Temporal.PlainDateTime
30
+ * PlainDateTime has year, month, day, hour properties but no timeZoneId
31
+ */
32
+ export declare function isPlainDateTime(value: any): boolean;
33
+ /**
34
+ * Check if a value is any Temporal type
35
+ */
36
+ export declare function isTemporal(value: any): boolean;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ /**
3
+ * Temporal Type Utilities
4
+ *
5
+ * Provides duck-typing helpers for checking Temporal types.
6
+ * Uses duck typing instead of instanceof to avoid issues with multiple
7
+ * instances of temporal-polyfill being loaded.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.isPlainDate = isPlainDate;
11
+ exports.isInstant = isInstant;
12
+ exports.isZonedDateTime = isZonedDateTime;
13
+ exports.isPlainTime = isPlainTime;
14
+ exports.isPlainDateTime = isPlainDateTime;
15
+ exports.isTemporal = isTemporal;
16
+ /**
17
+ * Check if a value is a Temporal.PlainDate
18
+ * PlainDate has year, month, day properties but no hour property
19
+ */
20
+ function isPlainDate(value) {
21
+ return value && typeof value === 'object' &&
22
+ typeof value.year === 'number' &&
23
+ typeof value.month === 'number' &&
24
+ typeof value.day === 'number' &&
25
+ typeof value.toString === 'function' &&
26
+ !value.hour; // PlainDate doesn't have hour
27
+ }
28
+ /**
29
+ * Check if a value is a Temporal.Instant
30
+ * Instant has epochNanoseconds property as a bigint
31
+ */
32
+ function isInstant(value) {
33
+ return value && typeof value === 'object' &&
34
+ typeof value.epochNanoseconds === 'bigint' &&
35
+ typeof value.toString === 'function';
36
+ }
37
+ /**
38
+ * Check if a value is a Temporal.ZonedDateTime
39
+ * ZonedDateTime has a timeZoneId property
40
+ */
41
+ function isZonedDateTime(value) {
42
+ return value && typeof value === 'object' &&
43
+ typeof value.timeZoneId === 'string' &&
44
+ typeof value.toString === 'function';
45
+ }
46
+ /**
47
+ * Check if a value is a Temporal.PlainTime
48
+ * PlainTime has hour and minute properties but no year
49
+ */
50
+ function isPlainTime(value) {
51
+ return value && typeof value === 'object' &&
52
+ typeof value.hour === 'number' &&
53
+ typeof value.minute === 'number' &&
54
+ typeof value.toString === 'function' &&
55
+ !value.year; // PlainTime doesn't have year
56
+ }
57
+ /**
58
+ * Check if a value is a Temporal.PlainDateTime
59
+ * PlainDateTime has year, month, day, hour properties but no timeZoneId
60
+ */
61
+ function isPlainDateTime(value) {
62
+ return value && typeof value === 'object' &&
63
+ typeof value.year === 'number' &&
64
+ typeof value.month === 'number' &&
65
+ typeof value.day === 'number' &&
66
+ typeof value.hour === 'number' &&
67
+ typeof value.toString === 'function' &&
68
+ !value.timeZoneId; // PlainDateTime doesn't have timeZoneId
69
+ }
70
+ /**
71
+ * Check if a value is any Temporal type
72
+ */
73
+ function isTemporal(value) {
74
+ return isPlainDate(value) ||
75
+ isInstant(value) ||
76
+ isZonedDateTime(value) ||
77
+ isPlainTime(value) ||
78
+ isPlainDateTime(value);
79
+ }
80
+ //# sourceMappingURL=temporal_utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"temporal_utils.js","sourceRoot":"","sources":["../../../src/grpc/temporal_utils.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AAMH,kCAOC;AAMD,8BAIC;AAMD,0CAIC;AAMD,kCAMC;AAMD,0CAQC;AAKD,gCAMC;AApED;;;GAGG;AACH,SAAgB,WAAW,CAAC,KAAU;IACpC,OAAO,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAClC,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;QAC9B,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ;QAC/B,OAAO,KAAK,CAAC,GAAG,KAAK,QAAQ;QAC7B,OAAO,KAAK,CAAC,QAAQ,KAAK,UAAU;QACpC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAE,8BAA8B;AACrD,CAAC;AAED;;;GAGG;AACH,SAAgB,SAAS,CAAC,KAAU;IAClC,OAAO,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAClC,OAAO,KAAK,CAAC,gBAAgB,KAAK,QAAQ;QAC1C,OAAO,KAAK,CAAC,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al-polyfill/global");
4
+ //# sourceMappingURL=test-setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-setup.js","sourceRoot":"","sources":["../../src/test-setup.ts"],"names":[],"mappings":";;AAAA,oCAAkC"}
@@ -0,0 +1,106 @@
1
+ /**
2
+ * ActionCable Client for Forthic
3
+ * Browser-compatible client that mirrors GrpcClient API
4
+ * Specifically designed for Rails ActionCable WebSocket protocol
5
+ */
6
+ import { StackValue } from './serializer.js';
7
+ export interface ModuleSummary {
8
+ name: string;
9
+ description: string;
10
+ word_count: number;
11
+ }
12
+ export interface WordInfo {
13
+ name: string;
14
+ stack_effect: string;
15
+ description: string;
16
+ }
17
+ export interface ModuleInfo {
18
+ module_name: string;
19
+ words: WordInfo[];
20
+ }
21
+ export interface ProgressUpdate {
22
+ step: number;
23
+ total_steps: number;
24
+ current_word: string;
25
+ message?: string;
26
+ partial_stack?: StackValue[];
27
+ }
28
+ export interface ActionCableClientConfig {
29
+ url: string;
30
+ timezone?: string;
31
+ reconnect?: boolean;
32
+ reconnectDelay?: number;
33
+ channel?: string;
34
+ }
35
+ /**
36
+ * ActionCable client for executing words in remote Forthic runtimes
37
+ * Mirrors the GrpcClient API for compatibility
38
+ * Uses Rails ActionCable WebSocket protocol
39
+ */
40
+ export declare class ActionCableClient {
41
+ private ws?;
42
+ private config;
43
+ private pendingRequests;
44
+ private messageId;
45
+ private connected;
46
+ private connectionPromise?;
47
+ constructor(config: ActionCableClientConfig);
48
+ /**
49
+ * Connect to the WebSocket server
50
+ */
51
+ private connect;
52
+ /**
53
+ * Handle incoming WebSocket messages
54
+ */
55
+ private handleMessage;
56
+ /**
57
+ * Generate next message ID
58
+ */
59
+ private nextMessageId;
60
+ /**
61
+ * Send a request and wait for response
62
+ * @template T The expected result type (the value of the `result` field)
63
+ */
64
+ private sendRequest;
65
+ /**
66
+ * Send a streaming request with progress callbacks
67
+ * @template T The expected result type (the value of the `result` field)
68
+ */
69
+ private sendStreamingRequest;
70
+ /**
71
+ * Ensure WebSocket is connected
72
+ */
73
+ private ensureConnected;
74
+ /**
75
+ * Execute a word in the remote runtime
76
+ * Mirrors GrpcClient.executeWord
77
+ */
78
+ executeWord(word: string, stack: any[]): Promise<any[]>;
79
+ /**
80
+ * Execute a sequence of words (batched execution)
81
+ * Mirrors GrpcClient.executeSequence
82
+ */
83
+ executeSequence(words: string[], stack: any[]): Promise<any[]>;
84
+ /**
85
+ * List available runtime-specific modules
86
+ * Mirrors GrpcClient.listModules
87
+ */
88
+ listModules(): Promise<ModuleSummary[]>;
89
+ /**
90
+ * Get detailed information about a specific module
91
+ * Mirrors GrpcClient.getModuleInfo
92
+ */
93
+ getModuleInfo(moduleName: string): Promise<ModuleInfo>;
94
+ /**
95
+ * Execute code with streaming progress updates (NEW capability)
96
+ */
97
+ streamingExecute(code: string, stack: any[], onProgress?: (progress: ProgressUpdate) => void): Promise<any[]>;
98
+ /**
99
+ * Close the WebSocket connection
100
+ */
101
+ close(): void;
102
+ /**
103
+ * Check if the client is connected
104
+ */
105
+ isConnected(): boolean;
106
+ }
@@ -0,0 +1,269 @@
1
+ "use strict";
2
+ /**
3
+ * ActionCable Client for Forthic
4
+ * Browser-compatible client that mirrors GrpcClient API
5
+ * Specifically designed for Rails ActionCable WebSocket protocol
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.ActionCableClient = void 0;
9
+ const serializer_js_1 = require("./serializer.js");
10
+ const errors_js_1 = require("./errors.js");
11
+ /**
12
+ * ActionCable client for executing words in remote Forthic runtimes
13
+ * Mirrors the GrpcClient API for compatibility
14
+ * Uses Rails ActionCable WebSocket protocol
15
+ */
16
+ class ActionCableClient {
17
+ ws;
18
+ config;
19
+ pendingRequests = new Map();
20
+ messageId = 0;
21
+ connected = false;
22
+ connectionPromise;
23
+ constructor(config) {
24
+ this.config = {
25
+ url: config.url,
26
+ timezone: config.timezone || 'UTC',
27
+ reconnect: config.reconnect ?? true,
28
+ reconnectDelay: config.reconnectDelay || 3000,
29
+ channel: config.channel || 'ForthicRuntimeChannel',
30
+ };
31
+ this.connect();
32
+ }
33
+ /**
34
+ * Connect to the WebSocket server
35
+ */
36
+ connect() {
37
+ if (this.connectionPromise) {
38
+ return this.connectionPromise;
39
+ }
40
+ this.connectionPromise = new Promise((resolve, reject) => {
41
+ try {
42
+ this.ws = new WebSocket(this.config.url);
43
+ this.ws.onopen = () => {
44
+ this.connected = true;
45
+ // Subscribe to ActionCable channel
46
+ const subscribeMessage = {
47
+ command: 'subscribe',
48
+ identifier: JSON.stringify({
49
+ channel: this.config.channel,
50
+ timezone: this.config.timezone,
51
+ }),
52
+ };
53
+ this.ws.send(JSON.stringify(subscribeMessage));
54
+ resolve();
55
+ };
56
+ this.ws.onmessage = (event) => {
57
+ this.handleMessage(event);
58
+ };
59
+ this.ws.onerror = (error) => {
60
+ console.error('WebSocket error:', error);
61
+ reject(new Error('WebSocket connection error'));
62
+ };
63
+ this.ws.onclose = () => {
64
+ this.connected = false;
65
+ this.connectionPromise = undefined;
66
+ // Reject all pending requests
67
+ for (const [id, pending] of this.pendingRequests.entries()) {
68
+ pending.reject(new Error('WebSocket connection closed'));
69
+ }
70
+ this.pendingRequests.clear();
71
+ // Attempt reconnect if enabled
72
+ if (this.config.reconnect) {
73
+ setTimeout(() => this.connect(), this.config.reconnectDelay);
74
+ }
75
+ };
76
+ }
77
+ catch (error) {
78
+ reject(error);
79
+ }
80
+ });
81
+ return this.connectionPromise;
82
+ }
83
+ /**
84
+ * Handle incoming WebSocket messages
85
+ */
86
+ handleMessage(event) {
87
+ try {
88
+ const data = JSON.parse(event.data);
89
+ // Handle ActionCable control messages
90
+ if (data.type === 'welcome' || data.type === 'ping' || data.type === 'confirm_subscription') {
91
+ return;
92
+ }
93
+ // Extract the actual message from ActionCable envelope
94
+ const message = data.message || data;
95
+ if (!message.id) {
96
+ console.warn('Received message without ID:', message);
97
+ return;
98
+ }
99
+ // Handle streaming progress updates
100
+ if (message.type === 'streaming_progress') {
101
+ const pending = this.pendingRequests.get(message.id);
102
+ if (pending?.onProgress) {
103
+ pending.onProgress(message.progress);
104
+ }
105
+ return;
106
+ }
107
+ // Handle final responses
108
+ const pending = this.pendingRequests.get(message.id);
109
+ if (!pending) {
110
+ console.warn('Received response for unknown request:', message.id);
111
+ return;
112
+ }
113
+ if (message.error) {
114
+ pending.reject(new errors_js_1.RemoteRuntimeError(message.error));
115
+ }
116
+ else {
117
+ pending.resolve(message.result);
118
+ }
119
+ this.pendingRequests.delete(message.id);
120
+ }
121
+ catch (error) {
122
+ console.error('Error handling WebSocket message:', error);
123
+ }
124
+ }
125
+ /**
126
+ * Generate next message ID
127
+ */
128
+ nextMessageId() {
129
+ return `msg-${++this.messageId}-${Date.now()}`;
130
+ }
131
+ /**
132
+ * Send a request and wait for response
133
+ * @template T The expected result type (the value of the `result` field)
134
+ */
135
+ async sendRequest(message) {
136
+ await this.ensureConnected();
137
+ return new Promise((resolve, reject) => {
138
+ this.pendingRequests.set(message.id, { resolve, reject });
139
+ // Wrap message in ActionCable format
140
+ const actionCableMessage = {
141
+ command: 'message',
142
+ identifier: JSON.stringify({
143
+ channel: this.config.channel,
144
+ }),
145
+ data: JSON.stringify(message),
146
+ };
147
+ this.ws.send(JSON.stringify(actionCableMessage));
148
+ });
149
+ }
150
+ /**
151
+ * Send a streaming request with progress callbacks
152
+ * @template T The expected result type (the value of the `result` field)
153
+ */
154
+ async sendStreamingRequest(message, onProgress) {
155
+ await this.ensureConnected();
156
+ return new Promise((resolve, reject) => {
157
+ this.pendingRequests.set(message.id, { resolve, reject, onProgress });
158
+ // Wrap message in ActionCable format
159
+ const actionCableMessage = {
160
+ command: 'message',
161
+ identifier: JSON.stringify({
162
+ channel: this.config.channel,
163
+ }),
164
+ data: JSON.stringify(message),
165
+ };
166
+ this.ws.send(JSON.stringify(actionCableMessage));
167
+ });
168
+ }
169
+ /**
170
+ * Ensure WebSocket is connected
171
+ */
172
+ async ensureConnected() {
173
+ if (!this.connected) {
174
+ await this.connect();
175
+ }
176
+ }
177
+ /**
178
+ * Execute a word in the remote runtime
179
+ * Mirrors GrpcClient.executeWord
180
+ */
181
+ async executeWord(word, stack) {
182
+ const message = {
183
+ type: 'execute_word',
184
+ id: this.nextMessageId(),
185
+ params: {
186
+ word,
187
+ stack: (0, serializer_js_1.serializeStack)(stack),
188
+ },
189
+ };
190
+ const result = await this.sendRequest(message);
191
+ return (0, serializer_js_1.deserializeStack)(result.stack);
192
+ }
193
+ /**
194
+ * Execute a sequence of words (batched execution)
195
+ * Mirrors GrpcClient.executeSequence
196
+ */
197
+ async executeSequence(words, stack) {
198
+ const message = {
199
+ type: 'execute_sequence',
200
+ id: this.nextMessageId(),
201
+ params: {
202
+ words,
203
+ stack: (0, serializer_js_1.serializeStack)(stack),
204
+ },
205
+ };
206
+ const result = await this.sendRequest(message);
207
+ return (0, serializer_js_1.deserializeStack)(result.stack);
208
+ }
209
+ /**
210
+ * List available runtime-specific modules
211
+ * Mirrors GrpcClient.listModules
212
+ */
213
+ async listModules() {
214
+ const message = {
215
+ type: 'list_modules',
216
+ id: this.nextMessageId(),
217
+ };
218
+ const result = await this.sendRequest(message);
219
+ return result.modules || [];
220
+ }
221
+ /**
222
+ * Get detailed information about a specific module
223
+ * Mirrors GrpcClient.getModuleInfo
224
+ */
225
+ async getModuleInfo(moduleName) {
226
+ const message = {
227
+ type: 'get_module_info',
228
+ id: this.nextMessageId(),
229
+ params: {
230
+ module_name: moduleName,
231
+ },
232
+ };
233
+ return await this.sendRequest(message);
234
+ }
235
+ /**
236
+ * Execute code with streaming progress updates (NEW capability)
237
+ */
238
+ async streamingExecute(code, stack, onProgress) {
239
+ const message = {
240
+ type: 'streaming_execute',
241
+ id: this.nextMessageId(),
242
+ params: {
243
+ code,
244
+ stack: (0, serializer_js_1.serializeStack)(stack),
245
+ },
246
+ };
247
+ const result = await this.sendStreamingRequest(message, onProgress);
248
+ return (0, serializer_js_1.deserializeStack)(result.stack);
249
+ }
250
+ /**
251
+ * Close the WebSocket connection
252
+ */
253
+ close() {
254
+ if (this.ws) {
255
+ this.config.reconnect = false; // Disable auto-reconnect
256
+ this.ws.close();
257
+ this.ws = undefined;
258
+ this.connected = false;
259
+ }
260
+ }
261
+ /**
262
+ * Check if the client is connected
263
+ */
264
+ isConnected() {
265
+ return this.connected;
266
+ }
267
+ }
268
+ exports.ActionCableClient = ActionCableClient;
269
+ //# sourceMappingURL=action_cable_client.js.map