@openlegion/platform 0.0.0-stage → 0.1.0

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 (120) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +1189 -2
  3. package/dist/body.d.ts +9 -0
  4. package/dist/body.js +28 -0
  5. package/dist/chat-history.d.ts +53 -0
  6. package/dist/chat-history.js +11 -0
  7. package/dist/client.d.ts +217 -0
  8. package/dist/client.js +367 -0
  9. package/dist/core.d.ts +47 -0
  10. package/dist/core.js +1 -0
  11. package/dist/crypto.d.ts +25 -0
  12. package/dist/crypto.js +81 -0
  13. package/dist/errors.d.ts +111 -0
  14. package/dist/errors.js +134 -0
  15. package/dist/events.d.ts +131 -0
  16. package/dist/events.js +5 -0
  17. package/dist/generated/api.d.ts +5505 -0
  18. package/dist/generated/api.js +446 -0
  19. package/dist/handler.d.ts +201 -0
  20. package/dist/handler.js +682 -0
  21. package/dist/index.d.ts +24 -0
  22. package/dist/index.js +12 -0
  23. package/dist/kit-agents.d.ts +95 -0
  24. package/dist/kit-agents.js +280 -0
  25. package/dist/kit-codes.d.ts +279 -0
  26. package/dist/kit-codes.js +44 -0
  27. package/dist/kit-connections.d.ts +21 -0
  28. package/dist/kit-connections.js +189 -0
  29. package/dist/kit-files.d.ts +8 -0
  30. package/dist/kit-files.js +117 -0
  31. package/dist/kit-model-keys.d.ts +8 -0
  32. package/dist/kit-model-keys.js +86 -0
  33. package/dist/kit-threads.d.ts +3 -0
  34. package/dist/kit-threads.js +92 -0
  35. package/dist/kit-tools.d.ts +21 -0
  36. package/dist/kit-tools.js +47 -0
  37. package/dist/kit.d.ts +130 -0
  38. package/dist/kit.js +155 -0
  39. package/dist/mcp-server.d.ts +27 -0
  40. package/dist/mcp-server.js +166 -0
  41. package/dist/next.d.ts +24 -0
  42. package/dist/next.js +6 -0
  43. package/dist/ol-signed.d.ts +82 -0
  44. package/dist/ol-signed.js +115 -0
  45. package/dist/react/add-server.d.ts +90 -0
  46. package/dist/react/add-server.js +183 -0
  47. package/dist/react/agent-chat.d.ts +925 -0
  48. package/dist/react/agent-chat.js +1917 -0
  49. package/dist/react/agent-editor.d.ts +133 -0
  50. package/dist/react/agent-editor.js +222 -0
  51. package/dist/react/agent-kit.d.ts +160 -0
  52. package/dist/react/agent-kit.js +279 -0
  53. package/dist/react/agent-list.d.ts +247 -0
  54. package/dist/react/agent-list.js +248 -0
  55. package/dist/react/approval-card.d.ts +272 -0
  56. package/dist/react/approval-card.js +372 -0
  57. package/dist/react/artifact-card.d.ts +38 -0
  58. package/dist/react/artifact-card.js +39 -0
  59. package/dist/react/avatar.d.ts +21 -0
  60. package/dist/react/avatar.js +33 -0
  61. package/dist/react/card-ledger.d.ts +30 -0
  62. package/dist/react/card-ledger.js +49 -0
  63. package/dist/react/chat-timing.d.ts +121 -0
  64. package/dist/react/chat-timing.js +229 -0
  65. package/dist/react/computer-view.d.ts +309 -0
  66. package/dist/react/computer-view.js +543 -0
  67. package/dist/react/computer-viewer.d.ts +175 -0
  68. package/dist/react/computer-viewer.js +555 -0
  69. package/dist/react/computer-wire.d.ts +178 -0
  70. package/dist/react/computer-wire.js +244 -0
  71. package/dist/react/connect-button.d.ts +145 -0
  72. package/dist/react/connect-button.js +212 -0
  73. package/dist/react/connection-request.d.ts +16 -0
  74. package/dist/react/connection-request.js +18 -0
  75. package/dist/react/connections-list.d.ts +90 -0
  76. package/dist/react/connections-list.js +76 -0
  77. package/dist/react/errors.d.ts +250 -0
  78. package/dist/react/errors.js +146 -0
  79. package/dist/react/files.d.ts +41 -0
  80. package/dist/react/files.js +78 -0
  81. package/dist/react/index.d.ts +35 -0
  82. package/dist/react/index.js +26 -0
  83. package/dist/react/limit-words.d.ts +80 -0
  84. package/dist/react/limit-words.js +53 -0
  85. package/dist/react/markdown.d.ts +42 -0
  86. package/dist/react/markdown.js +56 -0
  87. package/dist/react/md-parse.d.ts +106 -0
  88. package/dist/react/md-parse.js +638 -0
  89. package/dist/react/model-keys-card.d.ts +94 -0
  90. package/dist/react/model-keys-card.js +123 -0
  91. package/dist/react/reload.d.ts +211 -0
  92. package/dist/react/reload.js +339 -0
  93. package/dist/react/reveal.d.ts +17 -0
  94. package/dist/react/reveal.js +22 -0
  95. package/dist/react/schedule-editor.d.ts +107 -0
  96. package/dist/react/schedule-editor.js +172 -0
  97. package/dist/react/schedule-time.d.ts +66 -0
  98. package/dist/react/schedule-time.js +90 -0
  99. package/dist/react/styles.css +1274 -0
  100. package/dist/react/transport.d.ts +49 -0
  101. package/dist/react/transport.js +380 -0
  102. package/dist/react/use-connections.d.ts +155 -0
  103. package/dist/react/use-connections.js +231 -0
  104. package/dist/react/use-model-keys.d.ts +47 -0
  105. package/dist/react/use-model-keys.js +57 -0
  106. package/dist/react/use-threads.d.ts +63 -0
  107. package/dist/react/use-threads.js +73 -0
  108. package/dist/react/vault-form.d.ts +92 -0
  109. package/dist/react/vault-form.js +151 -0
  110. package/dist/schema.d.ts +47 -0
  111. package/dist/schema.js +16 -0
  112. package/dist/secrets.d.ts +15 -0
  113. package/dist/secrets.js +18 -0
  114. package/dist/stream.d.ts +129 -0
  115. package/dist/stream.js +192 -0
  116. package/dist/testing.d.ts +33 -0
  117. package/dist/testing.js +40 -0
  118. package/dist/webhooks.d.ts +31 -0
  119. package/dist/webhooks.js +72 -0
  120. package/package.json +85 -3
@@ -0,0 +1,31 @@
1
+ import { type SignatureFailure } from "./errors.ts";
2
+ import type { WebhookEvent } from "./events.ts";
3
+ import { type SecretInput } from "./secrets.ts";
4
+ export declare const WEBHOOK_SIGNATURE_HEADER = "openlegion-signature";
5
+ export declare const WEBHOOK_TOLERANCE_SECONDS = 300;
6
+ type HeaderBag = Headers | Record<string, string | string[] | undefined> | string | null | undefined;
7
+ export interface WebhookVerifyOptions {
8
+ /** Seconds either side of now. Default 300. */
9
+ toleranceSeconds?: number;
10
+ /** The receiver's clock. Default: now. */
11
+ now?: Date;
12
+ }
13
+ /** Why a signature fails, or null when it verifies. Never throws. */
14
+ export declare function webhookSignatureFailure(rawBody: string | Uint8Array | ArrayBuffer, header: string | null, secrets: readonly string[], opts?: WebhookVerifyOptions): Promise<SignatureFailure | null>;
15
+ /** Whether a webhook delivery's signature verifies. Never throws. */
16
+ declare function verifySignature(rawBody: string | Uint8Array | ArrayBuffer, headers: HeaderBag, secret: SecretInput, opts?: WebhookVerifyOptions): Promise<boolean>;
17
+ /**
18
+ * Verify a delivery and return its event, typed by `type`. Throws `SignatureVerificationError` (its
19
+ * `reason` says why) for anything that does not verify; never parse a body that fails.
20
+ *
21
+ * ```ts
22
+ * const event = await webhooks.constructEvent(await req.text(), req.headers, process.env.OPENLEGION_WEBHOOK_SECRET!);
23
+ * if (event.type === "run.completed") console.log(event.data.object?.id);
24
+ * ```
25
+ */
26
+ declare function constructEvent(rawBody: string | Uint8Array | ArrayBuffer, headers: HeaderBag, secret: SecretInput, opts?: WebhookVerifyOptions): Promise<WebhookEvent>;
27
+ export declare const webhooks: {
28
+ constructEvent: typeof constructEvent;
29
+ verifySignature: typeof verifySignature;
30
+ };
31
+ export {};
@@ -0,0 +1,72 @@
1
+ import { concat, hmacKey, hmacMatches, toBytes, utf8 } from "./crypto.js";
2
+ import { SignatureVerificationError } from "./errors.js";
3
+ import { liveSecrets } from "./secrets.js";
4
+ export const WEBHOOK_SIGNATURE_HEADER = "openlegion-signature";
5
+ export const WEBHOOK_TOLERANCE_SECONDS = 300;
6
+ function signatureFrom(headers) {
7
+ if (headers === null || headers === undefined)
8
+ return null;
9
+ if (typeof headers === "string")
10
+ return headers;
11
+ if (typeof headers.get === "function")
12
+ return headers.get(WEBHOOK_SIGNATURE_HEADER);
13
+ for (const [k, v] of Object.entries(headers)) {
14
+ if (k.toLowerCase() !== WEBHOOK_SIGNATURE_HEADER || v === undefined)
15
+ continue;
16
+ return Array.isArray(v) ? v.join(",") : v;
17
+ }
18
+ return null;
19
+ }
20
+ function parseLenient(header) {
21
+ let t = null;
22
+ const v1 = [];
23
+ for (const part of header.split(",")) {
24
+ const [k, v] = part.split("=", 2).map((s) => s.trim());
25
+ if (k === "t" && v && /^\d{1,12}$/.test(v))
26
+ t = Number(v);
27
+ else if (k === "v1" && v && /^[0-9a-f]{64}$/.test(v))
28
+ v1.push(v);
29
+ }
30
+ return { t, v1 };
31
+ }
32
+ export async function webhookSignatureFailure(rawBody, header, secrets, opts = {}) {
33
+ if (secrets.length === 0)
34
+ return "no_secret";
35
+ if (!header)
36
+ return "missing_headers";
37
+ const { t, v1 } = parseLenient(header);
38
+ if (t === null || v1.length === 0)
39
+ return "malformed_signature";
40
+ const nowS = Math.floor((opts.now ?? new Date()).getTime() / 1000);
41
+ if (Math.abs(nowS - t) > (opts.toleranceSeconds ?? WEBHOOK_TOLERANCE_SECONDS))
42
+ return "stale";
43
+ const signed = concat(utf8(`${t}.`), toBytes(rawBody));
44
+ for (const secret of secrets) {
45
+ const key = await hmacKey(secret);
46
+ for (const candidate of v1)
47
+ if (await hmacMatches(key, candidate, signed))
48
+ return null;
49
+ }
50
+ return "bad_signature";
51
+ }
52
+ const MESSAGES = {
53
+ no_secret: "No live webhook secret to verify with (OPENLEGION_WEBHOOK_SECRET, or the secret's grace has ended).",
54
+ missing_headers: "No OpenLegion-Signature header.",
55
+ malformed_signature: "OpenLegion-Signature has no t= or no v1=.",
56
+ stale: "OpenLegion-Signature's timestamp is outside the tolerance: a replay, or a clock that is off.",
57
+ bad_signature: "No v1= in OpenLegion-Signature matches this body under your secret(s).",
58
+ malformed_context: "The OpenLegion-Context header could not be read.",
59
+ };
60
+ async function verifySignature(rawBody, headers, secret, opts = {}) {
61
+ const secrets = liveSecrets(secret, (opts.now ?? new Date()).getTime());
62
+ return (await webhookSignatureFailure(rawBody, signatureFrom(headers), secrets, opts)) === null;
63
+ }
64
+ async function constructEvent(rawBody, headers, secret, opts = {}) {
65
+ const secrets = liveSecrets(secret, (opts.now ?? new Date()).getTime());
66
+ const failure = await webhookSignatureFailure(rawBody, signatureFrom(headers), secrets, opts);
67
+ if (failure)
68
+ throw new SignatureVerificationError(failure, MESSAGES[failure]);
69
+ const text = typeof rawBody === "string" ? rawBody : new TextDecoder().decode(toBytes(rawBody));
70
+ return JSON.parse(text);
71
+ }
72
+ export const webhooks = { constructEvent, verifySignature };
package/package.json CHANGED
@@ -1,6 +1,88 @@
1
1
  {
2
2
  "name": "@openlegion/platform",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "The OpenLegion Platform API client, and the kit that puts an agent in your app: your functions as its tools, webhooks and the chat stream, in one route.",
5
+ "license": "Apache-2.0",
6
+ "homepage": "https://openlegion.ai",
7
+ "keywords": [
8
+ "openlegion",
9
+ "ai-agents",
10
+ "agents",
11
+ "mcp",
12
+ "webhooks",
13
+ "nextjs",
14
+ "react"
15
+ ],
16
+ "type": "module",
17
+ "sideEffects": [
18
+ "*.css"
19
+ ],
20
+ "engines": {
21
+ "node": ">=22"
22
+ },
23
+ "main": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "default": "./dist/index.js"
29
+ },
30
+ "./next": {
31
+ "types": "./dist/next.d.ts",
32
+ "default": "./dist/next.js"
33
+ },
34
+ "./react": {
35
+ "types": "./dist/react/index.d.ts",
36
+ "default": "./dist/react/index.js"
37
+ },
38
+ "./react/styles.css": "./dist/react/styles.css",
39
+ "./testing": {
40
+ "types": "./dist/testing.d.ts",
41
+ "default": "./dist/testing.js"
42
+ }
43
+ },
44
+ "publishConfig": {
45
+ "access": "public"
46
+ },
47
+ "files": [
48
+ "dist",
49
+ "README.md",
50
+ "LICENSE"
51
+ ],
52
+ "peerDependencies": {
53
+ "@ai-sdk/react": ">=4.0.0 <5",
54
+ "ai": ">=7.0.0 <8",
55
+ "react": ">=19.0.0 <20"
56
+ },
57
+ "peerDependenciesMeta": {
58
+ "@ai-sdk/react": {
59
+ "optional": true
60
+ },
61
+ "ai": {
62
+ "optional": true
63
+ },
64
+ "react": {
65
+ "optional": true
66
+ }
67
+ },
68
+ "devDependencies": {
69
+ "@ai-sdk/react": "4.0.116",
70
+ "@types/node": "22.20.1",
71
+ "@types/react": "19.2.18",
72
+ "@types/react-dom": "19.2.4",
73
+ "ai": "7.0.113",
74
+ "react": "19.2.8",
75
+ "react-dom": "19.2.8",
76
+ "typescript": "5.9.3",
77
+ "vitest": "4.1.10",
78
+ "zod": "4.6.7",
79
+ "@openlegion/browser": "0.1.0"
80
+ },
81
+ "scripts": {
82
+ "build": "tsc -p tsconfig.build.json --removeComments --declaration false && tsc -p tsconfig.build.json --emitDeclarationOnly && cp src/react/styles.css dist/react/styles.css",
83
+ "typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.build.json",
84
+ "test": "vitest run --passWithNoTests --dir src",
85
+ "lint": "eslint src codegen",
86
+ "generate": "tsx codegen/generate.ts"
87
+ }
6
88
  }