@ai-accounts/vue-headless 0.2.2 → 0.3.0-alpha.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.
package/dist/index.cjs CHANGED
@@ -20,7 +20,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ aiAccountsKey: () => aiAccountsKey,
24
+ aiAccountsPlugin: () => aiAccountsPlugin,
23
25
  useAccountWizard: () => useAccountWizard,
26
+ useAiAccounts: () => useAiAccounts,
27
+ useBackendRegistry: () => useBackendRegistry,
28
+ useLoginSession: () => useLoginSession,
24
29
  useOnboarding: () => useOnboarding,
25
30
  version: () => version
26
31
  });
@@ -103,11 +108,163 @@ function useOnboarding(options) {
103
108
  };
104
109
  }
105
110
 
111
+ // src/injection-keys.ts
112
+ var aiAccountsKey = /* @__PURE__ */ Symbol("aiAccounts");
113
+
114
+ // src/plugin.ts
115
+ var aiAccountsPlugin = {
116
+ install(app, options) {
117
+ const onEvent = options.onEvent ?? (() => {
118
+ });
119
+ const emit = (event) => {
120
+ try {
121
+ onEvent(event);
122
+ } catch (err) {
123
+ try {
124
+ onEvent({
125
+ type: "internal.handler_error",
126
+ error: err instanceof Error ? err.message : String(err),
127
+ original: event
128
+ });
129
+ } catch {
130
+ }
131
+ }
132
+ };
133
+ const ctx = { client: options.client, emit };
134
+ app.provide(aiAccountsKey, ctx);
135
+ }
136
+ };
137
+
138
+ // src/composables/useAiAccounts.ts
139
+ var import_vue3 = require("vue");
140
+ function useAiAccounts() {
141
+ const ctx = (0, import_vue3.inject)(aiAccountsKey);
142
+ if (!ctx) {
143
+ throw new Error(
144
+ "useAiAccounts() called outside an app that installed aiAccountsPlugin"
145
+ );
146
+ }
147
+ return ctx;
148
+ }
149
+
150
+ // src/composables/useBackendRegistry.ts
151
+ var import_vue4 = require("vue");
152
+ function useBackendRegistry() {
153
+ const { client } = useAiAccounts();
154
+ const backends = (0, import_vue4.ref)([]);
155
+ const loaded = (0, import_vue4.ref)(false);
156
+ async function load() {
157
+ const result = await client.getBackendMetadata();
158
+ backends.value = result.items;
159
+ loaded.value = true;
160
+ }
161
+ function get(kind) {
162
+ return backends.value.find((m) => m.kind === kind);
163
+ }
164
+ return { backends, loaded, load, get };
165
+ }
166
+
167
+ // src/composables/useLoginSession.ts
168
+ var import_vue5 = require("vue");
169
+ function useLoginSession() {
170
+ const { client, emit } = useAiAccounts();
171
+ const status = (0, import_vue5.ref)("idle");
172
+ const sessionId = (0, import_vue5.ref)(null);
173
+ const accountId = (0, import_vue5.ref)(null);
174
+ const urlPrompt = (0, import_vue5.ref)(null);
175
+ const textPrompt = (0, import_vue5.ref)(null);
176
+ const stdoutLines = (0, import_vue5.ref)([]);
177
+ const errorCode = (0, import_vue5.ref)(null);
178
+ const errorMessage = (0, import_vue5.ref)(null);
179
+ async function start(id, flow, inputs) {
180
+ accountId.value = id;
181
+ status.value = "running";
182
+ urlPrompt.value = null;
183
+ textPrompt.value = null;
184
+ stdoutLines.value = [];
185
+ errorCode.value = null;
186
+ errorMessage.value = null;
187
+ const { session_id } = await client.beginLogin(id, flow, inputs);
188
+ sessionId.value = session_id;
189
+ emit({ type: "login.started", sessionId: session_id, backendKind: "", flow });
190
+ for await (const event of client.streamLogin(id, session_id)) {
191
+ dispatch(event);
192
+ if (status.value !== "running") return;
193
+ }
194
+ }
195
+ function dispatch(event) {
196
+ switch (event.type) {
197
+ case "url_prompt":
198
+ urlPrompt.value = event;
199
+ emit({ type: "login.prompt", sessionId: sessionId.value, promptKind: "url" });
200
+ break;
201
+ case "text_prompt":
202
+ textPrompt.value = event;
203
+ emit({ type: "login.prompt", sessionId: sessionId.value, promptKind: "text" });
204
+ break;
205
+ case "stdout":
206
+ stdoutLines.value = [...stdoutLines.value, event.text];
207
+ break;
208
+ case "progress":
209
+ break;
210
+ case "complete":
211
+ status.value = "complete";
212
+ accountId.value = event.account_id || accountId.value;
213
+ emit({
214
+ type: "login.completed",
215
+ sessionId: sessionId.value,
216
+ accountId: event.account_id
217
+ });
218
+ break;
219
+ case "failed":
220
+ status.value = "failed";
221
+ errorCode.value = event.code;
222
+ errorMessage.value = event.message;
223
+ emit({
224
+ type: "login.failed",
225
+ sessionId: sessionId.value,
226
+ code: event.code,
227
+ message: event.message
228
+ });
229
+ break;
230
+ }
231
+ }
232
+ async function respond(answer) {
233
+ if (!sessionId.value || !accountId.value || !textPrompt.value) return;
234
+ const promptId = textPrompt.value.prompt_id;
235
+ textPrompt.value = null;
236
+ await client.respondLogin(accountId.value, sessionId.value, promptId, answer);
237
+ }
238
+ async function cancel() {
239
+ if (!sessionId.value || !accountId.value) return;
240
+ await client.cancelLogin(accountId.value, sessionId.value);
241
+ status.value = "cancelled";
242
+ }
243
+ return {
244
+ status,
245
+ sessionId,
246
+ accountId,
247
+ urlPrompt,
248
+ textPrompt,
249
+ stdoutLines,
250
+ errorCode,
251
+ errorMessage,
252
+ start,
253
+ respond,
254
+ cancel
255
+ };
256
+ }
257
+
106
258
  // src/index.ts
107
- var version = "0.2.0";
259
+ var version = "0.3.0-alpha.1";
108
260
  // Annotate the CommonJS export names for ESM import in node:
109
261
  0 && (module.exports = {
262
+ aiAccountsKey,
263
+ aiAccountsPlugin,
110
264
  useAccountWizard,
265
+ useAiAccounts,
266
+ useBackendRegistry,
267
+ useLoginSession,
111
268
  useOnboarding,
112
269
  version
113
270
  });
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { Ref } from 'vue';
2
- import { AiAccountsClient, WizardState, DetectResultDTO, BackendDTO, OnboardingMachineState, OAuthDeviceLoginDTO } from '@ai-accounts/ts-core';
1
+ import { Ref, App, InjectionKey } from 'vue';
2
+ import { AiAccountsClient, WizardState, DetectResultDTO, BackendDTO, OnboardingMachineState, OAuthDeviceLoginDTO, AiAccountsEventHandler, AiAccountsEvent, BackendMetadata, UrlPrompt, TextPrompt, LoginFlowKind } from '@ai-accounts/ts-core';
3
3
 
4
4
  interface UseAccountWizardOptions {
5
5
  client: AiAccountsClient;
@@ -43,6 +43,46 @@ interface UseOnboardingReturn {
43
43
  }
44
44
  declare function useOnboarding(options: UseOnboardingOptions): UseOnboardingReturn;
45
45
 
46
- declare const version = "0.2.0";
46
+ type AiAccountsPluginOptions = {
47
+ client: AiAccountsClient;
48
+ onEvent?: AiAccountsEventHandler;
49
+ };
50
+ declare const aiAccountsPlugin: {
51
+ install(app: App, options: AiAccountsPluginOptions): void;
52
+ };
53
+
54
+ type AiAccountsContext = {
55
+ client: AiAccountsClient;
56
+ emit: (event: AiAccountsEvent) => void;
57
+ };
58
+ declare const aiAccountsKey: InjectionKey<AiAccountsContext>;
59
+
60
+ declare function useAiAccounts(): AiAccountsContext;
61
+
62
+ type Registry = {
63
+ backends: Ref<BackendMetadata[]>;
64
+ loaded: Ref<boolean>;
65
+ load: () => Promise<void>;
66
+ get: (kind: string) => BackendMetadata | undefined;
67
+ };
68
+ declare function useBackendRegistry(): Registry;
69
+
70
+ type LoginStatus = 'idle' | 'running' | 'complete' | 'failed' | 'cancelled';
71
+ type UseLoginSession = {
72
+ status: Ref<LoginStatus>;
73
+ sessionId: Ref<string | null>;
74
+ accountId: Ref<string | null>;
75
+ urlPrompt: Ref<UrlPrompt | null>;
76
+ textPrompt: Ref<TextPrompt | null>;
77
+ stdoutLines: Ref<string[]>;
78
+ errorCode: Ref<string | null>;
79
+ errorMessage: Ref<string | null>;
80
+ start: (accountId: string, flow: LoginFlowKind, inputs: Record<string, string>) => Promise<void>;
81
+ respond: (answer: string) => Promise<void>;
82
+ cancel: () => Promise<void>;
83
+ };
84
+ declare function useLoginSession(): UseLoginSession;
85
+
86
+ declare const version = "0.3.0-alpha.1";
47
87
 
48
- export { type UseAccountWizardOptions, type UseAccountWizardReturn, type UseOnboardingOptions, type UseOnboardingReturn, useAccountWizard, useOnboarding, version };
88
+ export { type AiAccountsContext, type AiAccountsPluginOptions, type LoginStatus, type UseAccountWizardOptions, type UseAccountWizardReturn, type UseLoginSession, type UseOnboardingOptions, type UseOnboardingReturn, aiAccountsKey, aiAccountsPlugin, useAccountWizard, useAiAccounts, useBackendRegistry, useLoginSession, useOnboarding, version };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Ref } from 'vue';
2
- import { AiAccountsClient, WizardState, DetectResultDTO, BackendDTO, OnboardingMachineState, OAuthDeviceLoginDTO } from '@ai-accounts/ts-core';
1
+ import { Ref, App, InjectionKey } from 'vue';
2
+ import { AiAccountsClient, WizardState, DetectResultDTO, BackendDTO, OnboardingMachineState, OAuthDeviceLoginDTO, AiAccountsEventHandler, AiAccountsEvent, BackendMetadata, UrlPrompt, TextPrompt, LoginFlowKind } from '@ai-accounts/ts-core';
3
3
 
4
4
  interface UseAccountWizardOptions {
5
5
  client: AiAccountsClient;
@@ -43,6 +43,46 @@ interface UseOnboardingReturn {
43
43
  }
44
44
  declare function useOnboarding(options: UseOnboardingOptions): UseOnboardingReturn;
45
45
 
46
- declare const version = "0.2.0";
46
+ type AiAccountsPluginOptions = {
47
+ client: AiAccountsClient;
48
+ onEvent?: AiAccountsEventHandler;
49
+ };
50
+ declare const aiAccountsPlugin: {
51
+ install(app: App, options: AiAccountsPluginOptions): void;
52
+ };
53
+
54
+ type AiAccountsContext = {
55
+ client: AiAccountsClient;
56
+ emit: (event: AiAccountsEvent) => void;
57
+ };
58
+ declare const aiAccountsKey: InjectionKey<AiAccountsContext>;
59
+
60
+ declare function useAiAccounts(): AiAccountsContext;
61
+
62
+ type Registry = {
63
+ backends: Ref<BackendMetadata[]>;
64
+ loaded: Ref<boolean>;
65
+ load: () => Promise<void>;
66
+ get: (kind: string) => BackendMetadata | undefined;
67
+ };
68
+ declare function useBackendRegistry(): Registry;
69
+
70
+ type LoginStatus = 'idle' | 'running' | 'complete' | 'failed' | 'cancelled';
71
+ type UseLoginSession = {
72
+ status: Ref<LoginStatus>;
73
+ sessionId: Ref<string | null>;
74
+ accountId: Ref<string | null>;
75
+ urlPrompt: Ref<UrlPrompt | null>;
76
+ textPrompt: Ref<TextPrompt | null>;
77
+ stdoutLines: Ref<string[]>;
78
+ errorCode: Ref<string | null>;
79
+ errorMessage: Ref<string | null>;
80
+ start: (accountId: string, flow: LoginFlowKind, inputs: Record<string, string>) => Promise<void>;
81
+ respond: (answer: string) => Promise<void>;
82
+ cancel: () => Promise<void>;
83
+ };
84
+ declare function useLoginSession(): UseLoginSession;
85
+
86
+ declare const version = "0.3.0-alpha.1";
47
87
 
48
- export { type UseAccountWizardOptions, type UseAccountWizardReturn, type UseOnboardingOptions, type UseOnboardingReturn, useAccountWizard, useOnboarding, version };
88
+ export { type AiAccountsContext, type AiAccountsPluginOptions, type LoginStatus, type UseAccountWizardOptions, type UseAccountWizardReturn, type UseLoginSession, type UseOnboardingOptions, type UseOnboardingReturn, aiAccountsKey, aiAccountsPlugin, useAccountWizard, useAiAccounts, useBackendRegistry, useLoginSession, useOnboarding, version };
package/dist/index.js CHANGED
@@ -79,10 +79,162 @@ function useOnboarding(options) {
79
79
  };
80
80
  }
81
81
 
82
+ // src/injection-keys.ts
83
+ var aiAccountsKey = /* @__PURE__ */ Symbol("aiAccounts");
84
+
85
+ // src/plugin.ts
86
+ var aiAccountsPlugin = {
87
+ install(app, options) {
88
+ const onEvent = options.onEvent ?? (() => {
89
+ });
90
+ const emit = (event) => {
91
+ try {
92
+ onEvent(event);
93
+ } catch (err) {
94
+ try {
95
+ onEvent({
96
+ type: "internal.handler_error",
97
+ error: err instanceof Error ? err.message : String(err),
98
+ original: event
99
+ });
100
+ } catch {
101
+ }
102
+ }
103
+ };
104
+ const ctx = { client: options.client, emit };
105
+ app.provide(aiAccountsKey, ctx);
106
+ }
107
+ };
108
+
109
+ // src/composables/useAiAccounts.ts
110
+ import { inject } from "vue";
111
+ function useAiAccounts() {
112
+ const ctx = inject(aiAccountsKey);
113
+ if (!ctx) {
114
+ throw new Error(
115
+ "useAiAccounts() called outside an app that installed aiAccountsPlugin"
116
+ );
117
+ }
118
+ return ctx;
119
+ }
120
+
121
+ // src/composables/useBackendRegistry.ts
122
+ import { ref as ref3 } from "vue";
123
+ function useBackendRegistry() {
124
+ const { client } = useAiAccounts();
125
+ const backends = ref3([]);
126
+ const loaded = ref3(false);
127
+ async function load() {
128
+ const result = await client.getBackendMetadata();
129
+ backends.value = result.items;
130
+ loaded.value = true;
131
+ }
132
+ function get(kind) {
133
+ return backends.value.find((m) => m.kind === kind);
134
+ }
135
+ return { backends, loaded, load, get };
136
+ }
137
+
138
+ // src/composables/useLoginSession.ts
139
+ import { ref as ref4 } from "vue";
140
+ function useLoginSession() {
141
+ const { client, emit } = useAiAccounts();
142
+ const status = ref4("idle");
143
+ const sessionId = ref4(null);
144
+ const accountId = ref4(null);
145
+ const urlPrompt = ref4(null);
146
+ const textPrompt = ref4(null);
147
+ const stdoutLines = ref4([]);
148
+ const errorCode = ref4(null);
149
+ const errorMessage = ref4(null);
150
+ async function start(id, flow, inputs) {
151
+ accountId.value = id;
152
+ status.value = "running";
153
+ urlPrompt.value = null;
154
+ textPrompt.value = null;
155
+ stdoutLines.value = [];
156
+ errorCode.value = null;
157
+ errorMessage.value = null;
158
+ const { session_id } = await client.beginLogin(id, flow, inputs);
159
+ sessionId.value = session_id;
160
+ emit({ type: "login.started", sessionId: session_id, backendKind: "", flow });
161
+ for await (const event of client.streamLogin(id, session_id)) {
162
+ dispatch(event);
163
+ if (status.value !== "running") return;
164
+ }
165
+ }
166
+ function dispatch(event) {
167
+ switch (event.type) {
168
+ case "url_prompt":
169
+ urlPrompt.value = event;
170
+ emit({ type: "login.prompt", sessionId: sessionId.value, promptKind: "url" });
171
+ break;
172
+ case "text_prompt":
173
+ textPrompt.value = event;
174
+ emit({ type: "login.prompt", sessionId: sessionId.value, promptKind: "text" });
175
+ break;
176
+ case "stdout":
177
+ stdoutLines.value = [...stdoutLines.value, event.text];
178
+ break;
179
+ case "progress":
180
+ break;
181
+ case "complete":
182
+ status.value = "complete";
183
+ accountId.value = event.account_id || accountId.value;
184
+ emit({
185
+ type: "login.completed",
186
+ sessionId: sessionId.value,
187
+ accountId: event.account_id
188
+ });
189
+ break;
190
+ case "failed":
191
+ status.value = "failed";
192
+ errorCode.value = event.code;
193
+ errorMessage.value = event.message;
194
+ emit({
195
+ type: "login.failed",
196
+ sessionId: sessionId.value,
197
+ code: event.code,
198
+ message: event.message
199
+ });
200
+ break;
201
+ }
202
+ }
203
+ async function respond(answer) {
204
+ if (!sessionId.value || !accountId.value || !textPrompt.value) return;
205
+ const promptId = textPrompt.value.prompt_id;
206
+ textPrompt.value = null;
207
+ await client.respondLogin(accountId.value, sessionId.value, promptId, answer);
208
+ }
209
+ async function cancel() {
210
+ if (!sessionId.value || !accountId.value) return;
211
+ await client.cancelLogin(accountId.value, sessionId.value);
212
+ status.value = "cancelled";
213
+ }
214
+ return {
215
+ status,
216
+ sessionId,
217
+ accountId,
218
+ urlPrompt,
219
+ textPrompt,
220
+ stdoutLines,
221
+ errorCode,
222
+ errorMessage,
223
+ start,
224
+ respond,
225
+ cancel
226
+ };
227
+ }
228
+
82
229
  // src/index.ts
83
- var version = "0.2.0";
230
+ var version = "0.3.0-alpha.1";
84
231
  export {
232
+ aiAccountsKey,
233
+ aiAccountsPlugin,
85
234
  useAccountWizard,
235
+ useAiAccounts,
236
+ useBackendRegistry,
237
+ useLoginSession,
86
238
  useOnboarding,
87
239
  version
88
240
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-accounts/vue-headless",
3
- "version": "0.2.2",
3
+ "version": "0.3.0-alpha.2",
4
4
  "description": "Vue 3 headless composables for ai-accounts",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -21,7 +21,7 @@
21
21
  "vue": "^3.4.0"
22
22
  },
23
23
  "dependencies": {
24
- "@ai-accounts/ts-core": "0.2.2"
24
+ "@ai-accounts/ts-core": "0.3.0-alpha.2"
25
25
  },
26
26
  "devDependencies": {
27
27
  "vue": "^3.4.0",