@qorejs/qore 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 (86) hide show
  1. package/README.md +170 -52
  2. package/dist/src/core/iterable.d.ts +1 -0
  3. package/dist/src/core/iterable.js +17 -0
  4. package/dist/src/core/response-runtime.d.ts +2 -0
  5. package/dist/src/core/response-runtime.js +233 -0
  6. package/dist/src/core/response-state.d.ts +3 -0
  7. package/dist/src/core/response-state.js +37 -0
  8. package/dist/src/core/response-types.d.ts +73 -0
  9. package/dist/src/core/response-types.js +1 -0
  10. package/dist/src/core/response.d.ts +4 -0
  11. package/dist/src/core/response.js +26 -0
  12. package/dist/src/core/signal-context.d.ts +10 -0
  13. package/dist/src/core/signal-context.js +69 -0
  14. package/dist/src/core/signal-nodes.d.ts +45 -0
  15. package/dist/src/core/signal-nodes.js +197 -0
  16. package/dist/src/core/signal-scheduler.d.ts +2 -0
  17. package/dist/src/core/signal-scheduler.js +19 -0
  18. package/dist/src/core/signal-types.d.ts +19 -0
  19. package/dist/src/core/signal-types.js +1 -0
  20. package/dist/src/core/signal.d.ts +19 -0
  21. package/dist/src/core/signal.js +41 -0
  22. package/dist/src/core/stream-backpressure.d.ts +3 -0
  23. package/dist/src/core/stream-backpressure.js +36 -0
  24. package/dist/src/core/stream-buffer.d.ts +17 -0
  25. package/dist/src/core/stream-buffer.js +162 -0
  26. package/dist/src/core/stream-iterator.d.ts +6 -0
  27. package/dist/src/core/stream-iterator.js +14 -0
  28. package/dist/src/core/stream-lifecycle.d.ts +10 -0
  29. package/dist/src/core/stream-lifecycle.js +28 -0
  30. package/dist/src/core/stream-queue.d.ts +17 -0
  31. package/dist/src/core/stream-queue.js +62 -0
  32. package/dist/src/core/stream-runtime.d.ts +2 -0
  33. package/dist/src/core/stream-runtime.js +127 -0
  34. package/dist/src/core/stream-source.d.ts +2 -0
  35. package/dist/src/core/stream-source.js +28 -0
  36. package/dist/src/core/stream-state.d.ts +4 -0
  37. package/dist/src/core/stream-state.js +20 -0
  38. package/dist/src/core/stream-types.d.ts +61 -0
  39. package/dist/src/core/stream-types.js +1 -0
  40. package/dist/src/core/stream.d.ts +11 -0
  41. package/dist/src/core/stream.js +90 -0
  42. package/dist/src/dom/app.d.ts +38 -0
  43. package/dist/src/dom/app.js +102 -0
  44. package/dist/src/dom/dom.d.ts +13 -0
  45. package/dist/src/dom/dom.js +197 -0
  46. package/dist/src/dom/properties.d.ts +3 -0
  47. package/dist/src/dom/properties.js +147 -0
  48. package/dist/src/dom/reactive.d.ts +6 -0
  49. package/dist/src/dom/reactive.js +14 -0
  50. package/dist/src/dom/response-view.d.ts +4 -0
  51. package/dist/src/dom/response-view.js +37 -0
  52. package/dist/src/dom/scope.d.ts +10 -0
  53. package/dist/src/dom/scope.js +49 -0
  54. package/dist/src/dom/types.d.ts +34 -0
  55. package/dist/src/dom/types.js +1 -0
  56. package/dist/src/index.d.ts +16 -0
  57. package/dist/src/index.js +10 -0
  58. package/dist/src/providers/anthropic.d.ts +2 -0
  59. package/dist/src/providers/anthropic.js +102 -0
  60. package/dist/src/providers/openai.d.ts +2 -0
  61. package/dist/src/providers/openai.js +96 -0
  62. package/dist/src/providers/sse-adapter.d.ts +2 -0
  63. package/dist/src/providers/sse-adapter.js +83 -0
  64. package/dist/src/providers/sse-env.d.ts +4 -0
  65. package/dist/src/providers/sse-env.js +33 -0
  66. package/dist/src/providers/sse-parser.d.ts +5 -0
  67. package/dist/src/providers/sse-parser.js +99 -0
  68. package/dist/src/providers/sse.d.ts +4 -0
  69. package/dist/src/providers/sse.js +3 -0
  70. package/dist/src/providers/types.d.ts +94 -0
  71. package/dist/src/providers/types.js +1 -0
  72. package/dist/src/shared/utils.d.ts +2 -0
  73. package/dist/src/shared/utils.js +32 -0
  74. package/package.json +25 -11
  75. package/src/anthropic.js +0 -122
  76. package/src/app.js +0 -123
  77. package/src/dom.js +0 -527
  78. package/src/index.d.ts +0 -405
  79. package/src/index.js +0 -10
  80. package/src/iterable.js +0 -20
  81. package/src/openai.js +0 -112
  82. package/src/response.js +0 -312
  83. package/src/signal.js +0 -328
  84. package/src/sse.js +0 -264
  85. package/src/stream.js +0 -582
  86. package/src/utils.js +0 -39
package/package.json CHANGED
@@ -1,27 +1,36 @@
1
1
  {
2
2
  "name": "@qorejs/qore",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "Qore is a streaming-response framework where stream becomes signal.",
5
5
  "type": "module",
6
- "main": "./src/index.js",
7
- "types": "./src/index.d.ts",
6
+ "main": "./dist/src/index.js",
7
+ "types": "./dist/src/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
- "types": "./src/index.d.ts",
11
- "import": "./src/index.js"
10
+ "types": "./dist/src/index.d.ts",
11
+ "import": "./dist/src/index.js"
12
12
  },
13
13
  "./package.json": "./package.json"
14
14
  },
15
15
  "files": [
16
- "src",
16
+ "dist/src",
17
17
  "README.md",
18
18
  "LICENSE"
19
19
  ],
20
20
  "sideEffects": false,
21
21
  "scripts": {
22
- "test": "node --test",
23
- "release:check": "npm test && npm pack --dry-run",
24
- "prepublishOnly": "npm run release:check"
22
+ "build": "node ./scripts/build.mjs",
23
+ "browsers:install": "playwright install chromium",
24
+ "typecheck": "node ./scripts/typecheck.mjs",
25
+ "check:dist": "node ./scripts/check-dist-sync.mjs",
26
+ "test:browser": "node ./scripts/browser-smoke.mjs",
27
+ "smoke:package-types": "node ./scripts/package-type-smoke.mjs",
28
+ "smoke:package-runtime": "node ./scripts/package-runtime-smoke.mjs",
29
+ "test": "node ./scripts/test.mjs",
30
+ "release:check": "node ./scripts/release-check.mjs",
31
+ "publish:github": "npm publish --registry=https://npm.pkg.github.com",
32
+ "publish:npm": "npm publish --access public",
33
+ "prepublishOnly": "node ./scripts/release-check.mjs"
25
34
  },
26
35
  "engines": {
27
36
  "node": ">=18.0.0"
@@ -39,7 +48,7 @@
39
48
  "framework",
40
49
  "async-iterable"
41
50
  ],
42
- "homepage": "https://github.com/qorejs/qore#readme",
51
+ "homepage": "https://qorejs.dev/",
43
52
  "repository": {
44
53
  "type": "git",
45
54
  "url": "git+https://github.com/qorejs/qore.git"
@@ -50,5 +59,10 @@
50
59
  "publishConfig": {
51
60
  "access": "public"
52
61
  },
53
- "license": "MIT"
62
+ "license": "MIT",
63
+ "devDependencies": {
64
+ "@playwright/test": "^1.60.0",
65
+ "@types/node": "^25.6.0",
66
+ "typescript": "^6.0.3"
67
+ }
54
68
  }
package/src/anthropic.js DELETED
@@ -1,122 +0,0 @@
1
- import { createSSEAdapter, readEnv } from './sse.js';
2
-
3
- const DEFAULT_BASE_URL = 'https://api.anthropic.com/v1';
4
- const DEFAULT_MODEL = 'claude-sonnet-4-20250514';
5
- const DEFAULT_VERSION = '2023-06-01';
6
- const DEFAULT_MAX_TOKENS = 1024;
7
-
8
- // Normalize single-string prompts into Anthropic's Messages API shape.
9
- function normalizeMessages(input) {
10
- if (typeof input === 'string') {
11
- return [{ role: 'user', content: input }];
12
- }
13
-
14
- if (Array.isArray(input)) {
15
- return input;
16
- }
17
-
18
- if (input && typeof input === 'object' && 'role' in input) {
19
- return [input];
20
- }
21
-
22
- return input;
23
- }
24
-
25
- // Keep provider setup explicit because real API keys should stay off the client.
26
- export function createAnthropic(options = {}) {
27
- const {
28
- apiKey,
29
- baseURL = DEFAULT_BASE_URL,
30
- model = DEFAULT_MODEL,
31
- version = DEFAULT_VERSION,
32
- maxTokens = DEFAULT_MAX_TOKENS,
33
- headers: defaultHeaders = {},
34
- fetch: fetchImpl = globalThis.fetch
35
- } = options;
36
- const resolvedApiKey = apiKey ?? readEnv('ANTHROPIC_API_KEY');
37
-
38
- if (!resolvedApiKey) {
39
- throw new Error('Qore Anthropic adapter requires an API key. Pass apiKey or set ANTHROPIC_API_KEY.');
40
- }
41
-
42
- const transport = createSSEAdapter({
43
- name: 'Anthropic',
44
- url: `${baseURL}/messages`,
45
- headers: {
46
- 'content-type': 'application/json',
47
- 'anthropic-version': version,
48
- 'x-api-key': resolvedApiKey,
49
- ...defaultHeaders
50
- },
51
- fetch: fetchImpl,
52
- buildRequest(request, requestOptions = {}) {
53
- const { signal, headers = {}, ...overrides } = requestOptions;
54
-
55
- return {
56
- method: 'POST',
57
- signal,
58
- headers,
59
- body: JSON.stringify({
60
- model,
61
- max_tokens: maxTokens,
62
- stream: true,
63
- ...request,
64
- ...overrides
65
- })
66
- };
67
- },
68
- parse: JSON.parse,
69
- isError: (event) => event.data?.type === 'error',
70
- getError: (event) => event.data?.error?.message ?? 'Anthropic streaming error',
71
- eventToText: (event) => (
72
- event.data?.type === 'content_block_delta'
73
- && event.data.delta?.type === 'text_delta'
74
- && typeof event.data.delta.text === 'string'
75
- )
76
- ? event.data.delta.text
77
- : undefined
78
- });
79
-
80
- async function* streamEvents(request, requestOptions = {}) {
81
- for await (const event of transport.stream(request, requestOptions)) {
82
- yield event.data;
83
- }
84
- }
85
-
86
- async function* streamText(messages, requestOptions = {}) {
87
- const request = messages && typeof messages === 'object' && 'messages' in messages
88
- ? messages
89
- : { messages };
90
-
91
- for await (const chunk of transport.streamText(request, requestOptions)) {
92
- yield chunk;
93
- }
94
- }
95
-
96
- return {
97
- // Stream typed semantic events from the Messages API.
98
- messages: {
99
- stream: streamEvents
100
- },
101
-
102
- // Stream only text delta chunks from assistant content blocks.
103
- streamText(messages, requestOptions = {}) {
104
- return streamText(messages, requestOptions);
105
- },
106
-
107
- // Match the Qore narrative directly: stream(anthropic.chat(prompt)).
108
- chat(input, requestOptions = {}) {
109
- const {
110
- signal,
111
- headers,
112
- ...request
113
- } = requestOptions;
114
-
115
- if (!('messages' in request)) {
116
- request.messages = normalizeMessages(input);
117
- }
118
-
119
- return streamText(request, { signal, headers });
120
- }
121
- };
122
- }
package/src/app.js DELETED
@@ -1,123 +0,0 @@
1
- import {
2
- dynamic,
3
- fragment,
4
- h,
5
- list,
6
- mount,
7
- renderResponse,
8
- show,
9
- text
10
- } from './dom.js';
11
- import { batch, computed, effect, signal, untrack } from './signal.js';
12
- import { response } from './response.js';
13
- import { from, mapStream, scanStream, stream } from './stream.js';
14
-
15
- // Resolve a CSS selector or direct node into the root mount target.
16
- function resolveTarget(target) {
17
- if (typeof document === 'undefined') {
18
- throw new Error('Qore app mounting requires a browser-like environment');
19
- }
20
-
21
- if (typeof target === 'string') {
22
- const element = document.querySelector(target);
23
-
24
- if (!element) {
25
- throw new Error(`Qore could not find a mount target for selector: ${target}`);
26
- }
27
-
28
- return element;
29
- }
30
-
31
- return target;
32
- }
33
-
34
- // Create a tiny application shell around Qore's lower-level primitives.
35
- export function createApp(setup) {
36
- let dispose = null;
37
- let mountedRoot = null;
38
- let cleanupHandlers = [];
39
-
40
- const app = {
41
- // Mount the app, provide framework primitives to setup, and render the resulting view.
42
- mount(target, props = {}) {
43
- const root = resolveTarget(target);
44
- app.unmount();
45
-
46
- cleanupHandlers = [];
47
- mountedRoot = root;
48
-
49
- // Expose the core runtime pieces so an app can stay entirely within Qore primitives.
50
- const context = {
51
- app,
52
- root,
53
- props,
54
- signal,
55
- computed,
56
- effect,
57
- batch,
58
- untrack,
59
- stream,
60
- from,
61
- mapStream,
62
- scanStream,
63
- response,
64
- h,
65
- text,
66
- dynamic,
67
- show,
68
- list,
69
- fragment,
70
- renderResponse,
71
- onCleanup(handler) {
72
- if (typeof handler === 'function') {
73
- cleanupHandlers.push(handler);
74
- }
75
-
76
- return handler;
77
- }
78
- };
79
-
80
- // Allow setup to return either a raw view or an object with lifecycle hooks.
81
- const result = setup(context);
82
- const view = result && typeof result === 'object' && 'view' in result
83
- ? result.view
84
- : result;
85
- const onMount = result && typeof result === 'object' ? result.onMount : null;
86
-
87
- dispose = mount(root, view);
88
-
89
- if (typeof onMount === 'function') {
90
- onMount(root);
91
- }
92
-
93
- return root;
94
- },
95
-
96
- // Tear down the mounted tree and any user-registered cleanup handlers.
97
- unmount() {
98
- if (dispose) {
99
- const stop = dispose;
100
- dispose = null;
101
- stop();
102
- }
103
-
104
- for (let index = cleanupHandlers.length - 1; index >= 0; index -= 1) {
105
- try {
106
- cleanupHandlers[index]();
107
- } catch {
108
- // Ignore user cleanup errors so the app can still unmount.
109
- }
110
- }
111
-
112
- cleanupHandlers = [];
113
- mountedRoot = null;
114
- return app;
115
- },
116
-
117
- get root() {
118
- return mountedRoot;
119
- }
120
- };
121
-
122
- return app;
123
- }