durable-actors 0.5.2 → 0.5.4

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 (82) hide show
  1. package/README.md +23 -26
  2. package/dist/actor/sandbox.d.ts +40 -0
  3. package/dist/actor/sandbox.d.ts.map +1 -0
  4. package/dist/actor/sandbox.js +32 -0
  5. package/dist/actor/sandbox.js.map +1 -0
  6. package/dist/actor/schema.d.ts +2 -0
  7. package/dist/actor/schema.d.ts.map +1 -1
  8. package/dist/actor/schema.js.map +1 -1
  9. package/dist/cli/actor-source-watcher.d.ts +18 -4
  10. package/dist/cli/actor-source-watcher.d.ts.map +1 -1
  11. package/dist/cli/actor-source-watcher.js +104 -34
  12. package/dist/cli/actor-source-watcher.js.map +1 -1
  13. package/dist/cli/dev.d.ts.map +1 -1
  14. package/dist/cli/dev.js +12 -1
  15. package/dist/cli/dev.js.map +1 -1
  16. package/dist/cli/generate.d.ts.map +1 -1
  17. package/dist/cli/generate.js +25 -6
  18. package/dist/cli/generate.js.map +1 -1
  19. package/dist/cli/python.d.ts +6 -0
  20. package/dist/cli/python.d.ts.map +1 -0
  21. package/dist/cli/python.js +50 -0
  22. package/dist/cli/python.js.map +1 -0
  23. package/dist/cli.js +14 -2
  24. package/dist/cli.js.map +1 -1
  25. package/dist/client/remoteClient.d.ts.map +1 -1
  26. package/dist/client/remoteClient.js +1 -10
  27. package/dist/client/remoteClient.js.map +1 -1
  28. package/dist/client-runtime/client.d.ts +0 -2
  29. package/dist/client-runtime/client.d.ts.map +1 -1
  30. package/dist/client-runtime/client.js +0 -3
  31. package/dist/client-runtime/client.js.map +1 -1
  32. package/dist/compiler/actor-compiler.d.ts +2 -0
  33. package/dist/compiler/actor-compiler.d.ts.map +1 -1
  34. package/dist/compiler/actor-compiler.js +9 -0
  35. package/dist/compiler/actor-compiler.js.map +1 -1
  36. package/dist/compiler/deployment-build.js +7 -0
  37. package/dist/compiler/deployment-build.js.map +1 -1
  38. package/dist/compiler/features/sandbox.d.ts +9 -0
  39. package/dist/compiler/features/sandbox.d.ts.map +1 -0
  40. package/dist/compiler/features/sandbox.js +50 -0
  41. package/dist/compiler/features/sandbox.js.map +1 -0
  42. package/dist/compiler/types.d.ts +8 -1
  43. package/dist/compiler/types.d.ts.map +1 -1
  44. package/dist/compiler/types.js +1 -0
  45. package/dist/compiler/types.js.map +1 -1
  46. package/dist/compiler/validate-public-contract.d.ts.map +1 -1
  47. package/dist/compiler/validate-public-contract.js +4 -0
  48. package/dist/compiler/validate-public-contract.js.map +1 -1
  49. package/dist/generated/client-runtime.d.ts.map +1 -1
  50. package/dist/generated/client-runtime.js +1 -1
  51. package/dist/generated/client-runtime.js.map +1 -1
  52. package/dist/host/actor-runtime.d.ts.map +1 -1
  53. package/dist/host/actor-runtime.js +2 -3
  54. package/dist/host/actor-runtime.js.map +1 -1
  55. package/dist/index.d.ts +2 -0
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +1 -0
  58. package/dist/index.js.map +1 -1
  59. package/dist/templates/actor/package.json +1 -1
  60. package/dist/templates/ai-chat/README.md +3 -25
  61. package/dist/templates/ai-chat/package.json +1 -1
  62. package/dist/templates/ai-chat/src/Chat.tsx +9 -2
  63. package/dist/templates/ai-chat/src/actors.ts +2 -3
  64. package/dist/templates/ai-chat/src/backend.ts +7 -2
  65. package/dist/templates/chat/README.md +1 -1
  66. package/dist/templates/chat/package.json +1 -1
  67. package/dist/templates/documents/README.md +1 -1
  68. package/dist/templates/documents/package.json +1 -1
  69. package/dist/templates/python/.env.example +1 -0
  70. package/dist/templates/python/README.md +7 -0
  71. package/dist/templates/python/gitignore +6 -0
  72. package/dist/templates/python/package.json +11 -0
  73. package/dist/templates/python/pnpm-workspace.yaml +2 -0
  74. package/dist/templates/python/pyproject.toml +8 -0
  75. package/dist/templates/python/src/actors.py +9 -0
  76. package/dist/wire/public-contract.d.ts +4 -0
  77. package/dist/wire/public-contract.d.ts.map +1 -1
  78. package/package.json +2 -2
  79. package/dist/actor/invocationContext.d.ts +0 -4
  80. package/dist/actor/invocationContext.d.ts.map +0 -1
  81. package/dist/actor/invocationContext.js +0 -10
  82. package/dist/actor/invocationContext.js.map +0 -1
@@ -6,7 +6,7 @@ import type { UIMessage } from "ai"
6
6
  const initialMessages: UIMessage[] = await fetch("/api/chat/lobby").then(response => response.json())
7
7
 
8
8
  function Chat() {
9
- const { messages, sendMessage, status, error } = useChat({ id: "lobby", messages: initialMessages })
9
+ const { messages, sendMessage, regenerate, status, error } = useChat({ id: "lobby", messages: initialMessages })
10
10
  const busy = status === "submitted" || status === "streaming"
11
11
 
12
12
  return (
@@ -29,7 +29,14 @@ function Chat() {
29
29
  </label>
30
30
  <button disabled={busy}>{busy ? "Thinking…" : "Send"}</button>
31
31
  </form>
32
- {error && <p role="alert">{error.message}</p>}
32
+ {error && (
33
+ <p role="alert">
34
+ {error.message}{" "}
35
+ <button onClick={() => regenerate()} disabled={busy}>
36
+ Retry
37
+ </button>
38
+ </p>
39
+ )}
33
40
  </main>
34
41
  )
35
42
  }
@@ -8,8 +8,7 @@ export class ChatHistory extends Actor {
8
8
  return this.messages
9
9
  }
10
10
 
11
- async append(message: UIMessage) {
12
- this.messages.push(message)
13
- return this.messages
11
+ async append(...messages: UIMessage[]) {
12
+ this.messages.push(...messages)
14
13
  }
15
14
  }
@@ -19,7 +19,8 @@ app.post("/api/chat", async (request, response) => {
19
19
  const [message] = await validateUIMessages({ messages: [request.body.messages.at(-1)] })
20
20
  if (message.role !== "user") return response.sendStatus(400)
21
21
  const chat = ChatHistory.get(request.body.id)
22
- const messages = await chat.append(message)
22
+ const messages = [...(await chat.load()), message]
23
+ let failed = false
23
24
  const result = streamText({
24
25
  model: openai("gpt-5-mini"),
25
26
  messages: await convertToModelMessages(messages)
@@ -30,8 +31,12 @@ app.post("/api/chat", async (request, response) => {
30
31
  stream: result.stream,
31
32
  originalMessages: messages,
32
33
  generateMessageId: generateId,
34
+ onError: () => {
35
+ failed = true
36
+ return "Reply failed. Check the API key and try again."
37
+ },
33
38
  onEnd: async ({ responseMessage, outcome }) => {
34
- if (outcome.status === "completed") await chat.append(responseMessage)
39
+ if (!failed && outcome.status === "completed") await chat.append(message, responseMessage)
35
40
  }
36
41
  })
37
42
  })
@@ -69,6 +69,6 @@ Everyone joins as a guest. Add authentication and room access checks before issu
69
69
 
70
70
  ## Development
71
71
 
72
- Both processes read `.env`; saved state lives in `.durable-actors/`. Actor code reloads automatically. After changing public actor types, restart `npm run dev` to regenerate the client. For multiple examples, set distinct `PORT`, `DURABLE_ACTORS_PORT`, and matching control-plane URLs; see [Run the examples together](../README.md).
72
+ Both processes read `.env`; saved state lives in `.durable-actors/`. Actor code reloads automatically. After changing public actor types, restart `npm run dev` to regenerate the client. For multiple examples, set distinct `PORT`, `DURABLE_ACTORS_PORT`, and matching control-plane URLs; see [Run the examples together](https://github.com/TerseAI/durable-actors/tree/main/examples#run-the-examples-together).
73
73
 
74
74
  `npm run build` generates clients, checks TypeScript, and builds the frontend.
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "dependencies": {
14
14
  "express": "^5.2.1",
15
- "durable-actors": "0.5.2",
15
+ "durable-actors": "0.5.4",
16
16
  "react": "^19.3.0",
17
17
  "react-dom": "^19.3.0"
18
18
  },
@@ -48,6 +48,6 @@ Editing pauses while disconnected. Reload to reconnect; unsaved edits are not st
48
48
 
49
49
  ## Development
50
50
 
51
- Both processes read `.env`; saved state lives in `.durable-actors/`. Actor code reloads automatically. After changing public actor types, restart `npm run dev` to regenerate the client. For multiple examples, set distinct `PORT`, `DURABLE_ACTORS_PORT`, and matching control-plane URLs; see [Run the examples together](../README.md).
51
+ Both processes read `.env`; saved state lives in `.durable-actors/`. Actor code reloads automatically. After changing public actor types, restart `npm run dev` to regenerate the client. For multiple examples, set distinct `PORT`, `DURABLE_ACTORS_PORT`, and matching control-plane URLs; see [Run the examples together](https://github.com/TerseAI/durable-actors/tree/main/examples#run-the-examples-together).
52
52
 
53
53
  `npm run build` generates clients, checks TypeScript, and builds the frontend.
@@ -19,7 +19,7 @@
19
19
  "@tiptap/y-tiptap": "^3.0.7",
20
20
  "express": "^5.2.1",
21
21
  "lib0": "^0.2.117",
22
- "durable-actors": "0.5.2",
22
+ "durable-actors": "0.5.4",
23
23
  "react": "^19.3.0",
24
24
  "react-dom": "^19.3.0",
25
25
  "yjs": "^13.6.32"
@@ -0,0 +1 @@
1
+ DURABLE_ACTORS_ENTRYPOINT=src/actors.py
@@ -0,0 +1,7 @@
1
+ # Python actors
2
+
3
+ Install Node.js 22+, Python 3.11+, and uv. Run `pnpm install`, `uv sync`, then `pnpm exec durable-actors dev`. The shared TypeScript CLI selects `.venv` and checks actor types before starting and reloading.
4
+
5
+ Edit `src/actors.py`. Write synchronous actor methods with ordinary `def`. Annotated fields persist by default; use `emitted()` for state broadcasts and `ephemeral()` for temporary values such as caches and service clients. From your client application, install `little-actors[codegen]` and run `pnpm exec durable-actors generate` against the running server. Generated Python clients include synchronous typed methods and models. Import `actors` from the generated package and use `actors.Counter.get("one")`; the SDK manages the HTTP connection pool. Actors with emitted fields also expose `actor.subscribe(callback)` for typed live state; close the returned subscription when finished. The CLI runs strict mypy after generation.
6
+
7
+ Set `DURABLE_ACTORS_PYTHON` to select another interpreter. `DURABLE_ACTORS_BINARY` selects a locally built runtime.
@@ -0,0 +1,6 @@
1
+ node_modules/
2
+ .venv/
3
+ .durable-actors/
4
+ .mypy_cache/
5
+ __pycache__/
6
+ generated/
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "durable-actors-example-python",
3
+ "private": true,
4
+ "dependencies": {
5
+ "durable-actors": "0.5.4"
6
+ },
7
+ "scripts": {
8
+ "dev": "durable-actors dev",
9
+ "generate": "durable-actors generate"
10
+ }
11
+ }
@@ -0,0 +1,2 @@
1
+ allowBuilds:
2
+ esbuild: true
@@ -0,0 +1,8 @@
1
+ [project]
2
+ name = "little-actors-example"
3
+ version = "0.1.0"
4
+ requires-python = ">=3.11"
5
+ dependencies = ["little-actors[codegen]==0.5.4"]
6
+
7
+ [tool.mypy]
8
+ strict = true
@@ -0,0 +1,9 @@
1
+ from little_actors import Actor
2
+
3
+
4
+ class Counter(Actor):
5
+ count: int = 0
6
+
7
+ def increment(self, amount: int = 1) -> int:
8
+ self.count += amount
9
+ return self.count
@@ -1,4 +1,5 @@
1
1
  import type { JSONSchema7 } from "json-schema";
2
+ import type { SandboxOptions } from "../actor/sandbox.js";
2
3
  import type { SocketContract } from "./contract.js";
3
4
  interface PublicActorContract {
4
5
  readonly version: 1;
@@ -11,6 +12,8 @@ interface TypeScriptContract {
11
12
  }
12
13
  interface ActorApi {
13
14
  readonly actorName: string;
15
+ readonly description?: string;
16
+ readonly sandbox?: SandboxOptions;
14
17
  readonly socket: SocketContract;
15
18
  readonly rpc: RpcContract;
16
19
  }
@@ -20,6 +23,7 @@ interface RpcContract {
20
23
  }
21
24
  interface RpcMethod {
22
25
  readonly name: string;
26
+ readonly description?: string;
23
27
  readonly parameters: readonly RpcParameter[];
24
28
  readonly result: {
25
29
  readonly kind: "void";
@@ -1 +1 @@
1
- {"version":3,"file":"public-contract.d.ts","sourceRoot":"","sources":["../../src/wire/public-contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAEnD,UAAU,mBAAmB;IACzB,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAA;IACnB,QAAQ,CAAC,MAAM,EAAE,SAAS,QAAQ,EAAE,CAAA;IACpC,QAAQ,CAAC,UAAU,EAAE,kBAAkB,CAAA;CAC1C;AAED,UAAU,kBAAkB;IACxB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CAC1D;AAED,UAAU,QAAQ;IACd,QAAQ,CAAC,SAAS,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B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACxB;AAED,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,mBAAmB,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,kBAAkB,EAAE,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "durable-actors",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "Provider-neutral actors for sandbox compute",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -93,7 +93,7 @@
93
93
  "vite": "^8.3.0",
94
94
  "ws": "^8.18.3",
95
95
  "zod": "^4.3.6",
96
- "durable-actors-observer": "0.5.2"
96
+ "durable-actors-observer": "0.5.4"
97
97
  },
98
98
  "devDependencies": {
99
99
  "@types/node": "^22.0.0",
@@ -1,4 +0,0 @@
1
- declare function runInActorInvocation<T>(operation: () => T): T;
2
- declare function currentActorInvocation(): true | undefined;
3
- export { currentActorInvocation, runInActorInvocation };
4
- //# sourceMappingURL=invocationContext.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"invocationContext.d.ts","sourceRoot":"","sources":["../../src/actor/invocationContext.ts"],"names":[],"mappings":"AAIA,iBAAS,oBAAoB,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,CAEtD;AAED,iBAAS,sBAAsB,IAAI,IAAI,GAAG,SAAS,CAElD;AAED,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,CAAA"}
@@ -1,10 +0,0 @@
1
- import { AsyncLocalStorage } from "node:async_hooks";
2
- const invocationStorage = new AsyncLocalStorage();
3
- function runInActorInvocation(operation) {
4
- return invocationStorage.run(true, operation);
5
- }
6
- function currentActorInvocation() {
7
- return invocationStorage.getStore();
8
- }
9
- export { currentActorInvocation, runInActorInvocation };
10
- //# sourceMappingURL=invocationContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"invocationContext.js","sourceRoot":"","sources":["../../src/actor/invocationContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAEpD,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,EAAQ,CAAA;AAEvD,SAAS,oBAAoB,CAAI,SAAkB;IAC/C,OAAO,iBAAiB,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;AACjD,CAAC;AAED,SAAS,sBAAsB;IAC3B,OAAO,iBAAiB,CAAC,QAAQ,EAAE,CAAA;AACvC,CAAC;AAED,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,CAAA"}