@stigmer/client 0.1.3 → 0.3.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 (76) hide show
  1. package/README.md +10 -0
  2. package/app-handover.d.ts +186 -0
  3. package/app-handover.d.ts.map +1 -0
  4. package/app-handover.js +630 -0
  5. package/app-handover.js.map +1 -0
  6. package/gen/agent.d.ts +2 -1
  7. package/gen/agent.d.ts.map +1 -1
  8. package/gen/agent.js +2 -0
  9. package/gen/agent.js.map +1 -1
  10. package/gen/organization.d.ts +2 -0
  11. package/gen/organization.d.ts.map +1 -1
  12. package/gen/organization.js +8 -0
  13. package/gen/organization.js.map +1 -1
  14. package/gen/run.d.ts +7 -1
  15. package/gen/run.d.ts.map +1 -1
  16. package/gen/run.js +23 -1
  17. package/gen/run.js.map +1 -1
  18. package/iam-principal.d.ts +11 -0
  19. package/iam-principal.d.ts.map +1 -1
  20. package/iam-principal.js +16 -0
  21. package/iam-principal.js.map +1 -1
  22. package/index.d.ts +11 -5
  23. package/index.d.ts.map +1 -1
  24. package/index.js +10 -3
  25. package/index.js.map +1 -1
  26. package/node.d.ts.map +1 -1
  27. package/node.js +12 -0
  28. package/node.js.map +1 -1
  29. package/package.json +9 -4
  30. package/platform.d.ts +41 -3
  31. package/platform.d.ts.map +1 -1
  32. package/platform.js +56 -3
  33. package/platform.js.map +1 -1
  34. package/run/format-elapsed.d.ts +10 -0
  35. package/run/format-elapsed.d.ts.map +1 -0
  36. package/run/format-elapsed.js +25 -0
  37. package/run/format-elapsed.js.map +1 -0
  38. package/run/step-words.d.ts +78 -0
  39. package/run/step-words.d.ts.map +1 -0
  40. package/run/step-words.js +316 -0
  41. package/run/step-words.js.map +1 -0
  42. package/run/tool-view.d.ts +49 -2
  43. package/run/tool-view.d.ts.map +1 -1
  44. package/run/tool-view.js +113 -17
  45. package/run/tool-view.js.map +1 -1
  46. package/run/turn-activity.d.ts +9 -7
  47. package/run/turn-activity.d.ts.map +1 -1
  48. package/run/turn-activity.js +24 -144
  49. package/run/turn-activity.js.map +1 -1
  50. package/run/turn-ending.d.ts +59 -0
  51. package/run/turn-ending.d.ts.map +1 -0
  52. package/run/turn-ending.js +405 -0
  53. package/run/turn-ending.js.map +1 -0
  54. package/run/turn-steps.d.ts +16 -0
  55. package/run/turn-steps.d.ts.map +1 -0
  56. package/run/turn-steps.js +65 -0
  57. package/run/turn-steps.js.map +1 -0
  58. package/session-events.d.ts +3 -1
  59. package/session-events.d.ts.map +1 -1
  60. package/session-events.js +1 -0
  61. package/session-events.js.map +1 -1
  62. package/src/app-handover.ts +777 -0
  63. package/src/gen/agent.ts +4 -1
  64. package/src/gen/organization.ts +7 -0
  65. package/src/gen/run.ts +21 -1
  66. package/src/iam-principal.ts +21 -0
  67. package/src/index.ts +55 -1
  68. package/src/node.ts +12 -0
  69. package/src/platform.ts +80 -3
  70. package/src/run/format-elapsed.ts +22 -0
  71. package/src/run/step-words.ts +360 -0
  72. package/src/run/tool-view.ts +133 -19
  73. package/src/run/turn-activity.ts +27 -146
  74. package/src/run/turn-ending.ts +487 -0
  75. package/src/run/turn-steps.ts +81 -0
  76. package/src/session-events.ts +4 -1
package/README.md CHANGED
@@ -10,6 +10,16 @@ npm install @stigmer/client @stigmer/apis @bufbuild/protobuf
10
10
 
11
11
  `@stigmer/apis` and `@bufbuild/protobuf` are peer dependencies.
12
12
 
13
+ ### Node.js
14
+
15
+ `@stigmer/client/node` (`createNodeClient`) connects over `@connectrpc/connect-node`, a third peer dependency. It is optional, so a browser app doesn't install it; a Node.js app that imports `@stigmer/client/node` adds it:
16
+
17
+ ```bash
18
+ npm install @stigmer/client @stigmer/apis @bufbuild/protobuf @connectrpc/connect-node
19
+ ```
20
+
21
+ Without it, Node.js stops with `Cannot find package '@connectrpc/connect-node'`. The client declares Node.js 22 (22.13 or newer) or Node.js 23.4 or newer.
22
+
13
23
  ## Quick Start
14
24
 
15
25
  ### Server-to-server (static API key)
@@ -0,0 +1,186 @@
1
+ /**
2
+ * The code that puts an agent's chat in a builder's own app: one source for
3
+ * the text every surface hands over (the console's agent page, and anything
4
+ * else that writes a builder's token route and chat), so each says exactly
5
+ * the same thing and a compiler can hold all of it (the docs snippet gate
6
+ * compiles every stack's output as whole files).
7
+ *
8
+ * Two files, for a server that signs people in:
9
+ *
10
+ * - a token route for the builder's backend, `GET /api/stigmer-token`,
11
+ * answering `{ accessToken, expiresAt }` (the shape `createTokenCache`
12
+ * takes), minted with an admin service account's key read from
13
+ * `STIGMER_API_KEY`; one per stack, on the stack's standard library
14
+ * (Node's `node:http`, Python's `http.server`, Go's `net/http`, the JDK's
15
+ * `com.sun.net.httpserver`), or a Next.js route handler. A standard
16
+ * library route is something every reader can compile and run as it
17
+ * stands, and its one minting call moves into any framework;
18
+ * - the chat for their React app, `<AgentChat>` behind `createTokenCache`,
19
+ * in the light or dark of the person's system, as most apps start out.
20
+ *
21
+ * Beside them, what the builder needs to see it run: a short page that shows
22
+ * the chat in a box with a height, and the settings file the backend reads
23
+ * its key and development user from (`appSettingsText`). Every file is named
24
+ * by its path in the builder's project: a Next.js app is one app, holding the
25
+ * route, the chat and the page, so one install covers it; the other stacks'
26
+ * backends serve a React app of its own, which holds the chat and the page.
27
+ * The client's Node transport (`@connectrpc/connect-node`, an optional peer
28
+ * of `@stigmer/client`) is installed only by a line whose files run
29
+ * `@stigmer/client/node`: the Node and Next.js routes. A React app of its own
30
+ * runs the chat in the browser and installs no transport.
31
+ *
32
+ * Who is signed in is the one thing Stigmer cannot know. Every route asks one
33
+ * function, `currentUser`, which the builder replaces with their own sign-in.
34
+ * Until then it answers the person named by `STIGMER_DEV_USER` while that is
35
+ * set, and nobody otherwise, so a route pasted into production unchanged
36
+ * refuses everyone rather than minting for whoever calls it.
37
+ *
38
+ * For a server that trusts every caller (`stigmer up`), only the chat, with
39
+ * no token at all: there is no one to sign in, and the server refuses to
40
+ * mint. That text says it is for development.
41
+ *
42
+ * The text carries no secret: the key is read from the environment, and the
43
+ * functions here never take one. Every value written into code (the
44
+ * organization, the agent, the address) is written as a string literal by
45
+ * `JSON.stringify`, whose escapes are valid in all five languages, so no
46
+ * value can break out of its literal. Framework-free and import-free, so the
47
+ * plain-Node docs gate loads the built module as it stands.
48
+ */
49
+ /** A backend the handover writes a token route for. */
50
+ export type AppHandoverStack = "nextjs" | "node" | "python" | "go" | "java";
51
+ /** The backends, in the order a picker offers them, with their names. */
52
+ export declare const APP_HANDOVER_STACKS: readonly {
53
+ readonly id: AppHandoverStack;
54
+ readonly name: string;
55
+ }[];
56
+ /**
57
+ * Which server the code talks to: `"sign-in"`, one that signs its callers in
58
+ * (Stigmer Cloud, or a self-hosted server with sign-in turned on), where a
59
+ * backend mints each user's token; `"local"`, one that trusts every caller,
60
+ * where the chat sends no token and there is no backend.
61
+ */
62
+ export type AppHandoverMode = "sign-in" | "local";
63
+ /** The language a handed-over block is written in, for highlighting. */
64
+ export type AppHandoverLanguage = "bash" | "xml" | "typescript" | "tsx" | "python" | "go" | "java";
65
+ /** A whole file to add, at its path in the builder's project. */
66
+ export interface AppHandoverSource {
67
+ /** The file's path in the builder's project ("server.ts", "app/api/stigmer-token/route.ts"). */
68
+ readonly file: string;
69
+ readonly language: AppHandoverLanguage;
70
+ /** The whole file. */
71
+ readonly code: string;
72
+ }
73
+ /** One file to add, and what to install for it. */
74
+ export interface AppHandoverFile extends AppHandoverSource {
75
+ /** The install command (or, for Java, the Maven dependency). */
76
+ readonly install: string;
77
+ readonly installLanguage: "bash" | "xml";
78
+ }
79
+ /** What the handover gives a builder. */
80
+ export interface AppHandover {
81
+ /** The token route, for a server that signs people in; absent for a local one. */
82
+ readonly backend?: AppHandoverFile;
83
+ /** The chat component for their React app. */
84
+ readonly chat: AppHandoverFile;
85
+ /**
86
+ * A page to try it: the chat mounted in a box with a height, beside the
87
+ * chat in the same app (`app/agent/page.tsx` for Next.js, the React app's
88
+ * `src/App.tsx` otherwise).
89
+ */
90
+ readonly page: AppHandoverSource;
91
+ /** Where the page opens once the app runs: `"/agent"` for Next.js, `"/"` for a React app of its own. */
92
+ readonly pagePath: string;
93
+ /**
94
+ * Whether the backend and the chat are one app (Next.js), so one install
95
+ * covers both (`backend.install`); otherwise each file names its own.
96
+ */
97
+ readonly oneApp: boolean;
98
+ /**
99
+ * The settings file the backend reads (`.env.local` for Next.js, `.env`
100
+ * otherwise), for a server that signs people in; its text is
101
+ * {@link appSettingsText}'s. Absent for a local server, which needs none.
102
+ */
103
+ readonly settingsFile?: string;
104
+ /**
105
+ * Whether the backend reads {@link settingsFile} as handed over: Next.js
106
+ * loads `.env.local` itself, and the Node route's run line passes
107
+ * `--env-file=.env`. Python's, Go's and Java's routes read their
108
+ * environment, so the values must reach it some other way. Absent for a
109
+ * local server.
110
+ */
111
+ readonly readsSettingsFile?: boolean;
112
+ }
113
+ /** What {@link buildAppHandover} writes the code for. */
114
+ export interface AppHandoverInput {
115
+ readonly mode: AppHandoverMode;
116
+ /** The backend, for the token route. The chat is the same for every stack. */
117
+ readonly stack: AppHandoverStack;
118
+ /** The Stigmer API's public address, `https://…` or `http://…`. */
119
+ readonly baseUrl: string;
120
+ /** The organization's slug. */
121
+ readonly org: string;
122
+ /** The agent's slug. */
123
+ readonly agent: string;
124
+ /**
125
+ * A published release of the SDKs (`"0.1.3"`), named in Java's Maven
126
+ * dependency. Without one, the dependency takes the newest 0.x release and
127
+ * says where to find it to pin it.
128
+ */
129
+ readonly sdkVersion?: string;
130
+ }
131
+ /** The path every token route serves and the chat fetches. */
132
+ export declare const APP_TOKEN_ROUTE = "/api/stigmer-token";
133
+ /** The environment variable the routes read the service account's key from. */
134
+ export declare const APP_API_KEY_VARIABLE = "STIGMER_API_KEY";
135
+ /** The environment variable naming the person a route signs in until the builder's own sign-in replaces it. */
136
+ export declare const APP_DEV_USER_VARIABLE = "STIGMER_DEV_USER";
137
+ /** The chat component's name, as the builder mounts it: `<StigmerAgentChat />`. */
138
+ export declare const APP_CHAT_COMPONENT = "StigmerAgentChat";
139
+ /** The port a standard-library route listens on when `PORT` is unset. */
140
+ export declare const APP_TOKEN_ROUTE_PORT = 3001;
141
+ /** What the settings file holds in place of the key while the key is not on screen: where the key goes. */
142
+ export declare const APP_API_KEY_PLACEHOLDER = "<paste your service account's key here>";
143
+ /** What the settings file holds in place of the developer's email while it is not known. */
144
+ export declare const APP_DEV_USER_PLACEHOLDER = "<your email>";
145
+ /** The values {@link appSettingsText} writes, each a placeholder when absent. */
146
+ export interface AppSettingsValues {
147
+ /** The service account's key, while it is on screen; never stored. */
148
+ readonly apiKey?: string;
149
+ /** The email of the person the route signs in until the app has a sign-in of its own. */
150
+ readonly devUser?: string;
151
+ }
152
+ /**
153
+ * The backend's settings file (`AppHandover.settingsFile`): the service
154
+ * account's key, and the person the route signs in while the app has no
155
+ * sign-in of its own. A value not given is a placeholder that says what
156
+ * goes there. A line break in a value is dropped, so a value is one line.
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * appSettingsText({ devUser: "ada@acme.example" });
161
+ * // STIGMER_API_KEY=<paste your service account's key here>
162
+ * // STIGMER_DEV_USER=ada@acme.example
163
+ * ```
164
+ */
165
+ export declare function appSettingsText(values?: AppSettingsValues): string;
166
+ /**
167
+ * The code that puts `org/agent`'s chat in a builder's app, for their stack.
168
+ *
169
+ * @throws {Error} when `baseUrl` is not an absolute `http://` or `https://` address
170
+ *
171
+ * @example
172
+ * ```typescript
173
+ * import { buildAppHandover } from "@stigmer/client";
174
+ *
175
+ * const { backend, chat, page } = buildAppHandover({
176
+ * mode: "sign-in",
177
+ * stack: "node",
178
+ * baseUrl: "https://api.stigmer.ai",
179
+ * org: "acme",
180
+ * agent: "variance-reporter",
181
+ * });
182
+ * // backend.file === "server.ts"; chat.file === "src/StigmerAgentChat.tsx"; page.file === "src/App.tsx"
183
+ * ```
184
+ */
185
+ export declare function buildAppHandover(input: AppHandoverInput): AppHandover;
186
+ //# sourceMappingURL=app-handover.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-handover.d.ts","source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